Skip to content

JIT: (bug) AV in CEEInfo::getObjectContent while compiling "ab".AsSpan(Idx[0], 2).ToArray() with an out-of-range constant index #137680

Closed

Description

@EgorBo

With an out-of-range constant index, assertion prop (optVNBasedFoldExpr_Call_Memmove) asks the VM for the content of the frozen string "ab" at a ~2GB offset. CEEInfo::getObjectContent does its bounds check in int, the check overflows and passes, and memcpy reads past the string. The process dies while JIT-compiling Test instead of throwing ArgumentOutOfRangeException.

Minimal Repro

using System;
using System.Runtime.CompilerServices;

class Program
{
    static ReadOnlySpan<int> Idx => [0x3FFFFFF8];

    [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
    static char[] Test() => "ab".AsSpan(Idx[0], 2).ToArray();

    static void Main()
    {
        try { Console.WriteLine(Test().Length); }
        catch (ArgumentOutOfRangeException) { Console.WriteLine("AOORE"); }
    }
}

Expected

AOORE

Actual

The process crashes during the JIT compilation of Test (exit code 0xC0000602 on a Checked build, AV in clr assert):

CORECLR! memcpy
CORECLR! CEEInfo::getObjectContent
CLRJIT! Compiler::GetImmutableDataFromAddress
CLRJIT! Compiler::optVNBasedFoldExpr_Call_Memmove
CLRJIT! Compiler::optVNBasedFoldExpr_Call
CLRJIT! VNAssertionPropVisitor::PostOrderVisit
CLRJIT! Compiler::optAssertionPropMain

Works (AOORE) with DOTNET_JITMinOpts=1 or with index 0x3FFFFFF0.

Regression?

Checked JIT/VM built from main (a5d7014cefc), win-x64. On release runtimes:

Runtime Result
11.0.0, 10.0.15, 10.0.12 crash: Fatal error. Internal CLR error. (0x80131506), exit 0xC0000005
9.0.23, 8.0.34 OK, prints AOORE

Looks like a regression between 9.0 and 10.0 (not bisected).

Notes

  • The source address VN is frozen "ab" + 12 + 2 * 0x3FFFFFF8 = obj + 0x7FFFFFFC. It passes the byteOffset <= INT32_MAX check in GetImmutableDataFromAddress, so the JIT calls getObjectContent(obj, buffer, size = 4, offset = 0x7FFFFFFC) even though the copy block is dead (the range check folds into a throw).
  • CEEInfo::getObjectContent (jitinterface.cpp) checks bufferSize + valueOffset <= (int)objRef->GetSize()) in int: 4 + 0x7FFFFFFC wraps to INT_MIN and passes. The check should be overflow-free, e.g. valueOffset <= objSize && bufferSize <= objSize - valueOffset. getStaticFieldContent may have the same pattern.

Activity

  1. added this to the 12.0.0 milestone on Nov 16, 2026
  2. added
    area-CodeGen-coreclr
    on Nov 16, 2026
  3. dotnet-policy-service commented on Nov 16, 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. added a commit that references this issue on Nov 17, 2026
    0073ebf
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

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions