Repository navigation
GH-3984: Reject negative lengths in DeltaLengthByteArrayValuesReader - #3985
Open
gitRasheed wants to merge 1 commit into
Open
gitRasheed wants to merge 1 commit into
gitRasheed wants to merge 1 commit into
Conversation
…eader DeltaLengthByteArrayValuesReader passed decoded lengths directly to ByteBufferInputStream without validating that they are non-negative. On a SingleBufferInputStream, a negative length returned an empty slice and rewound the stream position so subsequent values re-read earlier bytes without error. skip(int n) had the same issue on negative sums, missed negative lengths inside a positive sum, and could overflow an int sum into a negative value. DeltaByteArrayReader was also affected via its suffix reader. Validate each decoded length in readLength() and throw ParquetDecodingException when negative, and accumulate the skip total in a long.
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.
Rationale for this change
DeltaLengthByteArrayValuesReadercurrently passes decoded lengths directly toByteBufferInputStreamwithout checking for negative values:readBytes(),SingleBufferInputStream.slice(length)only checksbuffer.remaining() < length. A negative length returns an empty buffer and rewinds the stream position, causing subsequent values to re-read earlier bytes (for example, lengths[2, -2, 2]overabcdsilently decode to["ab", "", "ab"]). On aMultiBufferInputStream, a negative length silently returns an empty buffer.skip(int n), summing lengths in anintlets a negative length cancel out against positive lengths, lets a negative total rewindSingleBufferInputStream, and lets large valid lengths overflow anintto a negative value.DeltaByteArrayReaderdelegates suffix reading toDeltaLengthByteArrayValuesReader, soDELTA_BYTE_ARRAYpages hit the same bug.What changes are included in this PR?
readLength()inDeltaLengthByteArrayValuesReaderto throwParquetDecodingExceptionwhen a decoded length is negative, and use it in bothreadBytes()andskip(int n).skip(int n)as alongso summing non-negativeintlengths cannot overflow.TestDeltaLengthByteArrayandTestDeltaByteArraycoveringreadBytes(),skip(n)with a negative length inside a positive sum,skip(n)with lengths overflowingint, andDELTA_BYTE_ARRAYnegative suffix lengths.This aligns with Arrow C++ (
decoder.cc) and Spark's vectorized reader (VectorizedDeltaLengthByteArrayReader). Valid Parquet files only contain non-negative lengths, so valid data is unaffected.Are these changes tested?
Yes. Added four unit tests:
TestDeltaLengthByteArray.testNegativeLengthTestDeltaLengthByteArray.testSkipNegativeLengthTestDeltaLengthByteArray.testSkipLengthsOverflowingIntTestDeltaByteArray.testNegativeSuffixLengthAll four fail on
master(no exception thrown) and pass with the fix. Ranparquet-columntests, Spotless, and Apache RAT locally. Also verified end-to-end with crafted Parquet files read throughParquetReader,AvroParquetReader, andParquetFileReader(v1/v2 pages, uncompressed and Snappy,DELTA_LENGTH_BYTE_ARRAYandDELTA_BYTE_ARRAY), which return["ab", "", "ab"]without the fix and throwParquetDecodingExceptionwith it.Are there any user-facing changes?
Yes. Reading a corrupt
DELTA_LENGTH_BYTE_ARRAYorDELTA_BYTE_ARRAYpage with a negative value length now throwsParquetDecodingExceptioninstead of silently returning corrupted values. No public API changes.Closes #3984