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) Loop cloning drops bounds checks when an arr.Length + K loop limit overflows to a negative value #133823
optDeriveLoopCloningConditions only emits the arr.Length + offset >= 0 guard when the peeled limit offset is negative, but the 32-bit add also wraps negative for large positive offsets, so the check-free fast clone runs out of bounds.
b.Length + int.MaxValue wraps to -2147483645, so the decreasing loop must walk i below 0 and throw.
Expected
IndexOutOfRangeException
DOTNET_JitCloneLoops=0 produces this correct result.
Actual
Fatal error.
Exit code 0xC0000005. Silent out-of-bounds read from safe C#.
Notes
MatchLimit / NaturalLoopIterInfo::LimitOffset (src/coreclr/jit/flowgraph.cpp) peel the constant out of b.Length + K; loopcloning.cpp guards arr.Length + offset >= 0 only under if (iterInfo->LimitOffset < 0).
The derived conditions are only about the initial IV ((V03 GE 0) && (V03 LT V00.Length)), both true here, so the check-free clone is entered and i walks down through negative values.
Fix direction: emit the arr.Length + offset >= 0 condition for positive offsets too, or reject offsets where the add can overflow.
changed the title [-]JIT (bug): Loop cloning drops bounds checks when an arr.Length + K loop limit overflows to a negative value[/-][+]JIT: (bug) Loop cloning drops bounds checks when an arr.Length + K loop limit overflows to a negative value[/+]on Sep 16, 2026
@AndyAyersMS would you consider backporting the fix from #133834 to release/11.0?
It currently only exists in main (12.0). The repro still fails on the shipped 11.0 RC2 SDK (11.0.100-rc.2.26467.112), while 8.0.425, 9.0.318 and 10.0.401 all behave correctly, so this is a regression introduced during the 11.0 cycle rather than a long-standing bug — 11.0 would ship with it.
Note: this comment was produced by an AI agent; the repro was re-run against all four released SDKs to confirm the results above.
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): Loop cloning drops bounds checks when an arr.Length + K loop limit overflows to a negative value[/-][+]JIT: (bug) Loop cloning drops bounds checks when an arr.Length + K loop limit overflows to a negative value[/+]JIT: guard overflow in loop cloning offset limits (#133834)
JIT: guard overflow in loop cloning offset limits (dotnet#133834)
EgorBo commentedon Sep 18, 2026
Affected SDK versions:
EgorBo commentedon Sep 18, 2026
@AndyAyersMS would you consider backporting the fix from #133834 to
release/11.0?It currently only exists in
main(12.0). The repro still fails on the shipped 11.0 RC2 SDK (11.0.100-rc.2.26467.112), while 8.0.425, 9.0.318 and 10.0.401 all behave correctly, so this is a regression introduced during the 11.0 cycle rather than a long-standing bug — 11.0 would ship with it.Note: this comment was produced by an AI agent; the repro was re-run against all four released SDKs to confirm the results above.
[release/11.0] JIT: guard overflow in loop cloning offset limits (#13…