AVRO-4325: [Trevni] Validate column-file header counts and lengths before allocating - #3921
Open
iemejia wants to merge 1 commit into
Open
AVRO-4325: [Trevni] Validate column-file header counts and lengths before allocating#3921iemejia wants to merge 1 commit into
iemejia wants to merge 1 commit into
Conversation
The Trevni readers sized several allocations directly from values read from the file header/metadata without validating them against the input available. For a malformed, corrupted, or truncated file these counts/lengths could greatly exceed the bytes present, driving oversized allocations, or overflow to a negative size. Add a shared InputBuffer.checkLength/remaining helper that rejects a negative value and one that could not be backed by the bytes remaining, and apply it to: - ColumnFileReader.readHeader (column count) - ColumnDescriptor.ensureBlocksRead (block count) - InputBuffer.readBytes/readString (length-prefixed byte arrays) - ColumnValues.startBlock (compressed block size), which now also uses Math.addExact for the checksum size to guard against integer overflow. Reading a malformed file now fails fast with a clear IOException; valid files read unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
The Trevni readers sized several allocations directly from values read from the file header/metadata without validating them against the input actually available. For a malformed, corrupted, or truncated file these counts/lengths could greatly exceed the bytes present, driving oversized allocations, or overflow to a negative size.
This adds a shared
InputBuffer.remaining()/InputBuffer.checkLength(count, minBytesPerElement)helper that rejects a negative value and any value that could not be backed by the bytes remaining, and applies it to the reader paths that size allocations from header/metadata values:ColumnFileReader.readHeader— column countColumnDescriptor.ensureBlocksRead— block countInputBuffer.readBytes/readString— length-prefixed byte arraysColumnValues.startBlock— compressed block size; this path now also usesMath.addExactfor the+ checksum.size()addition to guard against integer overflow.Reading a malformed file now fails fast with a clear
IOException; valid files read unchanged.How was this patch tested?
TestColumnFile:oversizedColumnCountIsRejected— a file whose header column count is overwritten withInteger.MAX_VALUEnow fails fast instead of attempting a large allocation.trevni-coremodule test suite passes.JIRA