[release/11.0] JIT: guard overflow in loop cloning offset limits - #134350
Merged
Merged
Conversation
Positive array length offsets can wrap negative and let the fast clone run without bounds checks. Guard offsets that can overflow and add regression coverage for decreasing loops. Fixes #133823 > [!NOTE] > This pull request description was generated with GitHub Copilot. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 336fb408-8580-4f7b-b3e6-087280a6294a
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Member
|
@dotnet/jit-contrib ptal |
JulieLeeMSFT
approved these changes
Sep 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #133834 to release/11.0
/cc @AndyAyersMS
Customer Impact
Loop cloning can incorrectly remove array bounds checks when a positive
arr.Length + offsetloop limit overflows to a negative value. Safe C# can then perform an out-of-bounds read and terminate with a native access violation instead of throwingIndexOutOfRangeException. This reproduces on .NET 11 RC1 and RC2; .NET 10 is correct. See #133823.Regression
Introduced during the .NET 11 cycle by #129309, which extended loop cloning to handle span/stride and constant-offset limits.
Testing
Added regression coverage for decreasing loops with overflowing positive offsets. The test fails before the fix and verifies that the required bounds exception is preserved after the fix. The original PR also passed JIT CI; Mono exclusions were added because this is CoreCLR-specific loop-cloning coverage.
Risk
Low. The change is localized to loop-cloning condition derivation. It rejects offsets that cannot be represented safely instead of selecting the unchecked fast clone, so the fallback retains the existing bounds checks.