Skip to content

Integer overflow in rangecheck.cpp when lcns is int.MinValue #127639

Description

@GrabYourPitchforks

(Received this customer report through another work item database. Copying the details here so we can close out the other work item.)

There is a flaw in this block in RangeCheck::BetweenBounds and possibly in similar blocks in this class.

// At this point,
// upper limit = len + ucns. ucns < 0
// lower limit = len + lcns.
if (range.LowerLimit().IsBinOpArray())
{
int lcns = range.LowerLimit().GetConstant();
if (lcns >= 0 || -lcns > arrSize)
{
return false;
}
return (range.LowerLimit().vn == uLimitVN && lcns <= ucns);
}

If lcns is int.MinValue, then the expression -lcns evaluates as -int.MinValue, or just int.MinValue. The condition on line 211 improperly evaluates to false, line 213 gets skipped, and line 215 returns true.

Activity

  1. added
    area-CodeGen-coreclr
    on May 1, 2026
  2. added
    untriaged
    on May 1, 2026
  3. dotnet-policy-service commented on May 1, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
    See info in area-owners.md if you want to be subscribed.

  4. EgorBo commented on May 1, 2026

    @EgorBo
    Member

    Looks like this code hasn't been touched in ~10 years

  5. self-assigned this
    on May 1, 2026
  6. EgorBo commented on May 1, 2026

    @EgorBo
    Member

    I actually wasn't able to construct a test (at least for .NET 11.0) where the bug could kick in, but still worth handling..

  7. added a commit that references this issue on May 4, 2026
    aa2d370
  8. removed
    untriaged
    on May 4, 2026
  9. locked and limited conversation to collaborators on Jun 4, 2026
  10. added a commit that references this issue on Jul 15, 2026
    7099221
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions