1fanwang opened a new pull request, #51169:
URL: https://github.com/apache/arrow/pull/51169

   ### Rationale for this change
   
   Parsing an oversized decimal string can return `OK` with a wrapped value 
instead of rejecting the input. For the 51-digit input in 
https://github.com/apache/arrow/issues/49817, the returned integer is the input 
modulo 2^128 instead of the parsed value.
   
   ### What changes are included in this PR?
   
   The digit accumulator now reports carry beyond the destination limbs. The 
parser also rejects magnitudes outside the signed range before constructing the 
decimal value. Decimal32 and Decimal64 use the same carry check.
   
   This leaves precision, scale, and Gandiva rounding policy unchanged. It only 
prevents integer wrap from being reported as a successful parse.
   
   Closes https://github.com/apache/arrow/issues/49817
   
   ### Are these changes tested?
   
   | Scenario | Before | After |
   |---|---|---|
   | Oversized Decimal128 input | Returns `OK` with wrapped data | Returns 
`Invalid` |
   | Oversized Decimal256 input | Returns `OK` with wrapped data | Returns 
`Invalid` |
   | Existing `FromString` coverage | Not applicable | Passes |
   
   <details>
   <summary>Raw logs</summary>
   
   ```text
   $ cpp/build/debug/arrow-utility-test \
       
--gtest_filter='Decimal128Test.FromStringLimits:Decimal256Test.FromStringLimits'
   
   Before:
   Expected Decimal128::FromString(...) to fail with Invalid, but got OK
   Expected Decimal256::FromString(...) to fail with Invalid, but got OK
   2 FAILED TESTS
   
   $ cpp/build/debug/arrow-utility-test --gtest_filter='*FromString*'
   
   After:
   [==========] Running 48 tests from 7 test suites.
   [  PASSED  ] 48 tests.
   ```
   
   </details>
   
   ### Are there any user-facing changes?
   
   Yes. Decimal strings that exceed the target integer range now return 
`Invalid` instead of a corrupted value.
   
   **This PR contains a "Critical Fix".** It prevents the decimal parser from 
returning incorrect data after integer overflow.
   


-- 
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