Tolerant slicing (RFC FS-1077) returns an empty result when finish < start. On arrays and strings the length finish - start + 1 overflows when finish is close to Int32.MinValue, and the slice throws instead.
let m = System.Int32.MinValue
[| 1..5 |][3..m] // OutOfMemoryException
(Array2D.init 5 5 (+))[3..m, *] // OutOfMemoryException
"hello"[3..m] // ArgumentOutOfRangeException
[ 1..5 ][3..m] // [], lists are correct
[| 1..5 |][3..(m + 10)] // [||], no overflow
Expected: an empty array or string, as for lists.
Cause: GetArraySlice passes finish - start + 1 to GetArraySub. With start = 3 and finish = Int32.MinValue the result wraps to a large positive length. GetStringSlice and the 2D–4D slicers use the same arithmetic. Comparing finish < start before subtracting avoids it: after ComputeSlice, finish - start + 1 cannot overflow when finish >= start.
Found while checking the bound arithmetic for RFC FS-1351 (fsharp/fslang-design#849). SDK 11.0.100-rc.1.26420.103.
🤖 Generated with Claude Code
Tolerant slicing (RFC FS-1077) returns an empty result when
finish < start. On arrays and strings the lengthfinish - start + 1overflows whenfinishis close toInt32.MinValue, and the slice throws instead.Expected: an empty array or string, as for lists.
Cause:
GetArraySlicepassesfinish - start + 1toGetArraySub. Withstart = 3andfinish = Int32.MinValuethe result wraps to a large positive length.GetStringSliceand the 2D–4D slicers use the same arithmetic. Comparingfinish < startbefore subtracting avoids it: afterComputeSlice,finish - start + 1cannot overflow whenfinish >= start.Found while checking the bound arithmetic for RFC FS-1351 (fsharp/fslang-design#849). SDK 11.0.100-rc.1.26420.103.
🤖 Generated with Claude Code