1fanwang commented on code in PR #51169:
URL: https://github.com/apache/arrow/pull/51169#discussion_r3952490925


##########
cpp/src/arrow/util/decimal.cc:
##########
@@ -783,8 +784,25 @@ static inline void ShiftAndAdd(std::string_view input, 
uint64_t out[], size_t ou
       out[i] = static_cast<uint64_t>(tmp & 0xFFFFFFFFFFFFFFFFULL);
       chunk = static_cast<uint64_t>(tmp >> 64);
     }
+    if (chunk != 0) {

Review Comment:
   Done in 
https://github.com/apache/arrow/commit/0d5bf6d4bc2ffb22ad4f37783fdb6bb174da8e70.



##########
cpp/src/arrow/util/decimal.cc:
##########
@@ -783,8 +784,25 @@ static inline void ShiftAndAdd(std::string_view input, 
uint64_t out[], size_t ou
       out[i] = static_cast<uint64_t>(tmp & 0xFFFFFFFFFFFFFFFFULL);
       chunk = static_cast<uint64_t>(tmp >> 64);
     }
+    if (chunk != 0) {
+      return true;
+    }
     posn += group_size;
   }
+  return false;
+}
+
+static inline bool MagnitudeOverflowsSignedDecimal(const uint64_t out[], 
size_t out_size,

Review Comment:
   Done in 
https://github.com/apache/arrow/commit/0d5bf6d4bc2ffb22ad4f37783fdb6bb174da8e70.



##########
cpp/src/arrow/util/decimal_test.cc:
##########
@@ -550,6 +555,9 @@ TEST(Decimal256Test, FromStringLimits) {
   //     
Decimal256::FromString("-9999999999999999999999999999999999999999999999999999999999999999999999999999e1"));
   //   ASSERT_RAISES(Invalid,
   //     
Decimal256::FromString("99999999999999999999999999999999999999999999999999999999999999999999999999999"));
+  ASSERT_RAISES(Invalid, Decimal256::FromString(std::string(78, '9')));
+  ASSERT_RAISES(Invalid, 
Decimal256::FromString("5789604461865809771178549250434395392663"
+                                                
"4992332820282019728792003956564819968"));

Review Comment:
   Done in 
https://github.com/apache/arrow/commit/0d5bf6d4bc2ffb22ad4f37783fdb6bb174da8e70.



##########
cpp/src/arrow/util/decimal.cc:
##########
@@ -962,9 +977,9 @@ Status SimpleDecimalFromString(const char* type_name, 
std::string_view s,
 
   if (out != nullptr) {
     uint64_t value{0};
-    ShiftAndAdd(dec.whole_digits, &value, 1);
-    ShiftAndAdd(dec.fractional_digits, &value, 1);
-    if (value > static_cast<uint64_t>(
+    if (ShiftAndAddWithOverflow(dec.whole_digits, &value, 1, dec.sign == '-') 
||
+        ShiftAndAddWithOverflow(dec.fractional_digits, &value, 1, dec.sign == 
'-') ||
+        value > static_cast<uint64_t>(
                     std::numeric_limits<typename 
DecimalClass::ValueType>::max())) {

Review Comment:
   Done in 
https://github.com/apache/arrow/commit/aa6fc1e361b3c618e8f2ed275ee9ad47b341ad19.



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