Skip to content

Conversation

@sbomer
Copy link
Member

@sbomer sbomer commented Feb 2, 2026

Summary

Fixes #123833

The switch IL instruction interpreter in TypePreinit used > instead of >= when checking if the switch value exceeds the case count. Per ECMA-335, switch should fall through to the next instruction when value >= count, but the code only did this for value > count.

When the value exactly equals the case count, the code tried to read a non-existent jump table entry, corrupting the IL reader offset and causing an IndexOutOfRangeException during NativeAOT compilation.

Changes

  • TypePreinit.cs: Changed target > count to target >= count in the switch instruction handler
  • Preinitialization.cs: Added test case for the boundary condition (value == case count)

…et#123833)

The switch IL instruction interpreter used > instead of >= when checking
if the switch value exceeds the case count. Per ECMA-335, switch should
fall through to the next instruction when value >= count, but the code
only did this for value > count.

When value exactly equals count, the code tried to read a non-existent
jump table entry, corrupting the IL reader offset and causing an
IndexOutOfRangeException during NativeAOT compilation.

Added test case for the boundary condition (value == case count).
Copilot AI review requested due to automatic review settings February 2, 2026 19:42
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

ILC throws an IndexOutOfRangeException

3 participants