ORC-2166: [C++] Guard C++ integer arithmetic against overflow#2622
Open
ffacs wants to merge 3 commits into
Open
ORC-2166: [C++] Guard C++ integer arithmetic against overflow#2622ffacs wants to merge 3 commits into
ffacs wants to merge 3 commits into
Conversation
| hasNegativeLength |= value < 0; | ||
| size_t length = static_cast<size_t>(value); | ||
| size_t nextTotalLength = totalLength + length; | ||
| hasLengthOverflow |= nextTotalLength < totalLength; |
Member
There was a problem hiding this comment.
Like skip() method, shall we throw here instead of waiting for the whole loop is finished?
ffa2af2 to
0c3a0c7
Compare
0c3a0c7 to
266b26b
Compare
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?
This PR adds reusable checked integer arithmetic helpers for the C++ code:
addWithOverflowandmultiplyWithOverflow.The patch uses these helpers to reject overflow-prone arithmetic in reader and buffer paths, including direct string length accumulation, list/map length accumulation, dictionary offsets, float/double skip byte counts, union child counts,
DataBufferallocation sizes,BlockBuffersize/capacity calculations, and list/map vector offset capacity calculations.Regression tests were added for the overflow helpers and malformed string/list/map length streams.
Why are the changes needed?
Malformed ORC files can provide invalid or extremely large values in length streams. Negative lengths or overflowing length sums can cause unchecked integer wraparound, incorrectly sized allocations, wrapped offsets, or unsafe skip/copy behavior.
Centralizing checked arithmetic makes these cases fail cleanly before unsafe allocation or memory access. Reader-facing malformed input now fails with
ParseError.How was this patch tested?
Ran the full C++ test target:
Result:
1/2 Test #1: orc-test .... Passed
2/2 Test #2: tool-test .... Passed
100% tests passed, 0 tests failed out of 2
Also ran targeted tests during development for the new overflow checks.
Was this patch authored or co-authored using generative AI tooling?
Yes. Generated with OpenAI Codex.