dmitry-chirkov-dremio commented on code in PR #52451:
URL: https://github.com/apache/arrow/pull/52451#discussion_r4304667671


##########
cpp/src/arrow/compute/kernels/scalar_string_ascii.cc:
##########
@@ -2642,7 +2642,10 @@ struct SliceBytesTransform : StringSliceTransformBase {
       // on the resulting slice lengths, so return a worst case estimate.
       return input_bytes;
     }
-    int64_t max_slice_bytes = (opt.stop - opt.start + opt.step - 1) / opt.step;
+    // SliceOptions uses INT64_MIN/MAX for open-ended bounds. Clamp stop before
+    // arithmetic so equivalent out-of-range indices cannot overflow the size 
estimate.
+    const int64_t stop = std::clamp(opt.stop, -input_bytes, input_bytes);
+    int64_t max_slice_bytes = (stop - opt.start + opt.step - 1) / opt.step;

Review Comment:
   This fixes the default stop case, but the calculation can still overflow 
with valid values. 
   Check start=INT64_MIN, stop=-1, and step=1 overflows at INT64_MAX + 1. 



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