GH-50057: [C++] Avoid signed overflow in Decimal FromString exponent#50058
Merged
pitrou merged 2 commits intoJun 25, 2026
Merged
Conversation
|
|
|
|
Signed-off-by: Sayed Kaif <metsw24@gmail.com>
Contributor
Author
|
Pushed a clang-format fixup for the C++ Format lint failure, rest of the change is unchanged. |
pitrou
approved these changes
Jun 25, 2026
pitrou
left a comment
Member
There was a problem hiding this comment.
Thanks for this @metsw24-max , let's just wait for CI
|
After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit b43a417. There was 1 benchmark result indicating a performance regression:
The full Conbench report has more details. It also includes information about 15 possible false positives for unstable benchmarks that are known to sometimes produce them. |
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
Decimal{32,64,128,256}::FromStringparse the exponent asint32_t, so a string like0E-2147483648reachesDecimalFromString/SimpleDecimalFromStringwithdec.exponent == INT32_MINand negating it is UB:A near-
INT32_MINexponent overflows the-exponent + fractional_digitsaddition the same way. Both helpers are reachable from the CSV/JSON readers parsing decimal columns.What changes are included in this PR?
Compute the scale via
internal::SubtractWithOverflowand reject the unrepresentable exponents withStatus::Invalid, in both helpers.Are these changes tested?
Yes,
0E-2147483648and1.0E-2147483647added toDecimalFromStringTest.InvalidInput(runs for Decimal32/64/128/256).Are there any user-facing changes?
No.