You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JIT: (bug) Bounds check incorrectly eliminated — range analysis ignores signed underflow of x + negativeConstant #133820
RangeCheck removes an array bounds check for an index computed as x + <negative constant> without accounting for signed underflow of the addition. The result is a silent out-of-bounds read instead of IndexOutOfRangeException.
int.MinValue + (-2147483640) wraps to 8, and arr.Length == 8, so the indexer must throw:
Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Program.Test(Int32 x)
at Program.Main()
Actual
UB
No CORINFO_HELP_RNGCHKFAIL is emitted. DOTNET_JITMinOpts=1 throws correctly.
Notes
x64, main @ 6ed2ba318dcaa936da60f7d6bc9eb30cad54fc0c; also reproduces on .NET 10.0.12 Release, so not a regression (not bisected further).
Also happens with a heap array (store arr into a static to force escape), turning it into an out-of-bounds heap read.
Root cause: from x <= int.MaxValue - 1 the JIT derives y <= 6, and with the dominating y >= 0 concludes y in [0, 6]. RangeCheck::AddOverflows / GetLimitMax (src/coreclr/jit/rangecheck.cpp) only test the operands' upper limits, so underflow at the lower end — one operand a negative constant, the other's lower limit unconstrained at int.MinValue — is never detected.
changed the title [-]JIT (bug): Bounds check incorrectly eliminated — range analysis ignores signed underflow of `x + negativeConstant`[/-][+]JIT: (bug) Bounds check incorrectly eliminated — range analysis ignores signed underflow of `x + negativeConstant`[/+]on Sep 16, 2026
Activity
dotnet-policy-service commentedon Sep 13, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
[-]JIT (bug): Bounds check incorrectly eliminated — range analysis ignores signed underflow of `x + negativeConstant`[/-][+]JIT: (bug) Bounds check incorrectly eliminated — range analysis ignores signed underflow of `x + negativeConstant`[/+]EgorBo commentedon Sep 18, 2026
Affected SDK versions:
x - int.MinValuedrops the upper bound (wrong result) #136366 as a duplicate of this issueJIT: Account for underflow in RangeCheck overflow checks
JIT: Account for underflow in RangeCheck AddOverflows and MultiplyOve…