metsw24-max opened a new pull request, #50058:
URL: https://github.com/apache/arrow/pull/50058

   ### Rationale for this change
   
   `Decimal{32,64,128,256}::FromString` parse the exponent as `int32_t`, so a 
string like `0E-2147483648` reaches 
`DecimalFromString`/`SimpleDecimalFromString` with `dec.exponent == INT32_MIN` 
and negating it is UB:
   
   ```
   decimal.cc: runtime error: negation of -2147483648 cannot be represented in 
type 'int32_t' (aka 'int')
   ```
   
   A near-`INT32_MIN` exponent overflows the `-exponent + fractional_digits` 
addition 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::SubtractWithOverflow` and reject the 
unrepresentable exponents with `Status::Invalid`, in both helpers.
   
   ### Are these changes tested?
   
   Yes, `0E-2147483648` and `1.0E-2147483647` added to 
`DecimalFromStringTest.InvalidInput` (runs for Decimal32/64/128/256).
   
   ### Are there any user-facing changes?
   
   No.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to