GH-50078: [C++][ORC] Avoid signed overflow when converting timestamps#50035
Open
jmestwa-coder wants to merge 2 commits into
Open
GH-50078: [C++][ORC] Avoid signed overflow when converting timestamps#50035jmestwa-coder wants to merge 2 commits into
jmestwa-coder wants to merge 2 commits into
Conversation
Member
|
Member
|
I agree with @kou. Changes like this require an issue. The change itself looks good. |
Author
|
Opened #50078 for this and retitled the PR to reference it. Also restored the PR template. Thanks both. |
|
|
Member
|
Thanks for updating it! Is it possible to add a test case? |
Author
|
Added one in adapter_test.cc (TimestampOutOfRangeIsRejected) - it feeds a far-future ORC timestamp (10000000000s, ~year 2286) through AppendBatch and asserts it returns Invalid instead of overflowing. |
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
A far-future ORC timestamp (after ~2262) makes
AppendTimestampBatchincpp/src/arrow/adapters/orc/util.ccoverflow int64 nanoseconds inseconds * kOneSecondNanos + nanos. Reducing the multiply under-fsanitize=signed-integer-overflow:What changes are included in this PR?
Detect the overflow with
MultiplyWithOverflow/AddWithOverflowand returnStatus::Invalidfor out-of-range values instead of computing the product with undefined behavior. Null slots are skipped.Are these changes tested?
Verified the offending expression with a standalone
-fsanitize=signed-integer-overflowreproducer and confirmed the patched path returns an error rather than overflowing.Are there any user-facing changes?
No.