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 removes bounds checks from an unsigned countdown loop whose induction variable underflows #133824
Loop cloning treats an unsigned decrementing loop as monotone, so the IV can wrap below the limit (0 - k → huge uint) and the bounds-check-free fast clone reads far out of bounds.
i walks 7, 4, 1, then 1 - 3 wraps to 0xFFFFFFFE, which is still > lo under the unsigned comparison, so a[i] must throw.
Expected
IndexOutOfRangeException
Actual
Fatal error.
Exit code 0xC0000005. The fast clone indexes a with 0xFFFFFFFE (~16 GB past the array base) — an out-of-bounds read from plain safe C#.
Notes
NaturalLoopIterInfo::IsDecreasingLoop() (src/coreclr/jit/flowgraph.cpp) does not consider TestTree->IsUnsigned(), so an unsigned GT_GT is accepted as a plain decreasing test even though it is not monotone under wraparound.
The derived cloning conditions a != null && n >= 0 && lo >= 0 && n < a.Length only constrain the initial IV; nothing proves the IV cannot step past the limit.
Any n/lo with (n - lo) % step != 0 hits it. Fix direction: bail out (or add conditions, e.g. step divides init - limit) when the test is unsigned.
Not a regression: also reproduces on released .NET 10.0.12.
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 removes bounds checks from an unsigned countdown loop whose induction variable underflows[/-][+]JIT: (bug) Loop cloning removes bounds checks from an unsigned countdown loop whose induction variable underflows[/+]EgorBo commentedon Sep 18, 2026
Affected SDK versions:
JIT: Guard loop cloning against unsigned decreasing IV wraparound (do…