GH-3449: Fix BinaryStats int overflow#3448
Open
Jiayi-Wang-db wants to merge 2 commits intoapache:masterfrom
Open
GH-3449: Fix BinaryStats int overflow#3448Jiayi-Wang-db wants to merge 2 commits intoapache:masterfrom
Jiayi-Wang-db wants to merge 2 commits intoapache:masterfrom
Conversation
wgtmac
reviewed
Mar 17, 2026
| PrimitiveType type = Types.required(BINARY).named("test_binary"); | ||
| Statistics<?> stats = Statistics.getBuilderForReading(type).build(); | ||
|
|
||
| byte[] largeValue = new byte[1_073_741_824]; // 2^30 = 1 GB |
Member
There was a problem hiding this comment.
Do we really need to allocate such large memory in the test?
Use Binary.fromConstantByteArray with a fake large length instead of allocating a real 1 GB byte array. The test only exercises length() arithmetic in isSmallerThan, so the backing bytes are never accessed.
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
BinaryStatistics.isSmallerThan()computesmin.length() + max.length()asint + int. When a binary column contains values >= 2^30 bytes (1 GB), this sum overflows to a negative number, which is then incorrectly evaluated as smaller thanMAX_STATS_SIZE(4096). This causes the full multi-GB min/max statistics to be serialized into the Thrift footer instead of being dropped, resulting in a corrupted Parquet file whose footer exceeds the 4-byte length field and cannot be read back.What changes are included in this PR?
Promote int arithmetic to long before addition in
BinaryStatistics.isSmallerThan()andisSmallerThanWithTruncation()to prevent integer overflow when binary values are very large.Are these changes tested?
Yes. Added a unit test in TestStatistics that creates a 1 GB binary value and asserts isSmallerThan(4096) correctly returns false.
Are there any user-facing changes?
Parquet files with very large binary values (>= 1 GB) will no longer have corrupted footers. The oversized statistics are now correctly dropped, producing a valid and readable file.
Closes #3449