ORC-2167: [C++] Fix integer overflow in PostScript footer length validation#2629
Open
luffy-zh wants to merge 2 commits into
Open
ORC-2167: [C++] Fix integer overflow in PostScript footer length validation#2629luffy-zh wants to merge 2 commits into
luffy-zh wants to merge 2 commits into
Conversation
…dation Added overflow-safe bounds checking in three locations in Reader.cc: 1. readMetadata() - check footer/metadata/postscript lengths before bounds validation 2. createReader() - check footer/postscript lengths before calculating tailSize 3. startNextStripe() - check stripe offset/length values Added unit tests to verify malformed ORC files with extremely large footer_length or metadata_length values throw ParseError instead of causing integer overflow or crash: - testMalformedFooterLengthOverflow - testMalformedMetadataLengthOverflow
Use compiler built-in for safer and cleaner overflow detection in Reader.cc metadata, stripe info, and postscript footer validations. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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?
Added overflow-safe bounds checking in three locations in c++/src/Reader.cc using __builtin_add_overflow to prevent integer overflow when parsing malformed
ORC files with extremely large length values in PostScript:
against fileLength
comparing against fileLength
Why are the changes needed?
When an ORC file's PostScript is crafted with footer_length or metadata_length set to UINT64_MAX, the bounds check using unsigned addition (e.g.,
metadataSize + footerLength + postscriptLength_ + 1) can overflow and wrap around to a small value, bypassing validation.
For example, given a 58-byte file with footerLength = UINT64_MAX, metadataSize = 0, and postscriptLength_ = 23:
Using __builtin_add_overflow (a GCC/Clang builtin) provides a standard, efficient way to detect overflow without manual subtraction logic.
How was this patch tested?
Added two unit tests in c++/test/TestReader.cc:
ParseError
Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude code