Skip to content

ARM64 JIT includes both ValueTuple<Int32,Int32> fields in a bounds-checked array index #138205

In review

Description

@Hekinen93

Description

A small, dependency-free C# console application aborts with System.AccessViolationException on macOS ARM64 under official .NET 10.0.14, 10.0.15, and 11.0.0 runtimes. The reproduction uses ordinary tuple construction, an object-reference array, and Dictionary. Its project explicitly sets AllowUnsafeBlocks=false.

The argument is (Id=168, Tag=-1), and only Id is used as the array index. The array has 4096 elements. The generated ARM64 code checks the lower 32-bit register w1 against the length, then calculates the destination using the full 64-bit register x1, which still contains both tuple fields (0xffffffff000000a8). A debugger capture confirms that the resulting invalid address exactly matches the destination of the faulting store.

The primary reproduction contains no MemoryMarshal, Unsafe APIs, pointers, P/Invoke, package references, or game/editor dependencies. It was extracted while diagnosing a crash in a larger managed simulation.

Reproduction Steps

Create a net10.0 console project using the following files.

ManagedFields.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
    <NuGetAudit>false</NuGetAudit>
  </PropertyGroup>
</Project>

Program.cs

using System.Runtime.CompilerServices;

var cache = new Cache();
var value = new Value();
var keys = new (int Id, int Tag)[1];
keys[0] = (168, args.Contains("--zero-tag") ? 0 : -1);
Console.WriteLine($"Runtime={Environment.Version}; Id={keys[0].Id}; Tag={keys[0].Tag}");
for (int pass = 0; pass < 12; pass++)
{
    for (int i = 0; i < 100_000; i++) cache.Commit(keys[0], value);
    Thread.Sleep(100);
}
Console.WriteLine("PASS ordinary tuple fields");

sealed class Value { }
sealed class Cache
{
    private readonly Value?[] values = new Value?[4096];
    private readonly Dictionary<(int Id, int Tag), Value?> groups = new();
    [MethodImpl(MethodImplOptions.NoInlining)]
    public void Commit((int Id, int Tag) key, Value? value)
    {
        if ((uint)key.Id < (uint)values.Length) values[key.Id] = value;
        else groups[key] = value;
    }
}

Build and execute the compiled assembly.

dotnet build ManagedFields.csproj -c Release
dotnet bin/Release/net10.0/ManagedFields.dll

The default ARM64 run normally aborts in less than one second on the tested machine. A zero-tag control uses the same assembly.

dotnet bin/Release/net10.0/ManagedFields.dll --zero-tag

The control prints PASS ordinary tuple fields. To inspect the generated method on macOS, run

DOTNET_JitDisasm='Cache:Commit' DOTNET_JitStdOutFile=commit.jit dotnet bin/Release/net10.0/ManagedFields.dll

The identical net10.0 assembly was also executed with a side-by-side .NET 11.0.0 runtime using

DOTNET_ROLL_FORWARD=Major /path/to/dotnet11/dotnet bin/Release/net10.0/ManagedFields.dll

The attachment contains this project, both control projects, and the measured evidence.

Expected behavior

Every write should target values[168], which is within the 4096-element array. The Tag field should have no effect on the array address. The application should print PASS ordinary tuple fields and exit successfully.

Actual behavior

The process aborts with SIGABRT on macOS, represented as -6 by Python and 134 by shell.

Runtime=10.0.15; Id=168; Tag=-1
Fatal error.
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Cache.Commit(System.ValueTuple`2<Int32,Int32>, Value)
   at Program.<Main>$(System.String[])

The following counts refer to the ordinary-C# (int Id, int Tag) reproduction above. Each setting was tested separately.

| Runtime and architecture | Default crashes | OSR-off crashes | PGO-off crashes | Tiering-off crashes | Tag=0 passes |

10.0.14, macOS ARM64 10/10 | 5/5 | 3/3 | 3/3 | 3/3
10.0.15, macOS ARM64 |10/10 | 5/5 | 3/3 | 3/3 | 3/3
11.0.0, macOS ARM64 10/10 | 5/5 | 3/3 | 3/3 | 3/3
10.0.15, macOS x64 under Rosetta 0/3 | 0/3 | 0/3 | 0/3 | 3/3

The settings were DOTNET_TC_OnStackReplacement=0, DOTNET_TieredPGO=0, and DOTNET_TieredCompilation=0. The first process for each condition captured JIT disassembly. The remaining repeats ran without JIT logging.

A fault-time LLDB capture on official .NET 10.0.15 ARM64 with OSR disabled recorded

Id=168
Tag=-1
array=0x12ae15c98
array_length=4096
packed_tuple_x1=0xffffffff000000a8
expected_slot=0x12ae161e8
actual_slot_x14=0xfffffff92ae161e8
full_tuple_slot=0xfffffff92ae161e8
address_matches=True

The actual slot exactly equals array + 16 + 8 * packed_tuple_x1 modulo 2^64. The first store in the write barrier, stlr x15, [x14], faults at that destination. The full saved context and disassembly are in the attachment.

Regression?

The first affected release is unknown. This standalone reproduction was tested on .NET 10.0.14, 10.0.15, and 11.0.0. Earlier runtime releases have not been tested. The macOS x64 control passed under Rosetta on the same Apple Silicon machine. Windows, Linux, other ARM64 hardware, and native Intel/AMD machines have not been tested.

Known Workarounds

An equivalent standalone control changes the method to accept Id and Tag as separate Int32 parameters and reconstructs the tuple only for the dictionary fallback. It passed 3/3 default runs on each tested runtime/architecture combination. The complete control project is included in the attachment.

Changing Tag to zero also passes 3/3 runs on each ARM64 runtime, but that changes the input data and serves only as a diagnostic control.

Disabling OSR, PGO, or tiered compilation individually still crashes the primary (int,int) reproduction. Those settings therefore do not provide a general workaround. A compiler-source repair has not been implemented.

Configuration

  • macOS 27.2.1, build 26B131, on Apple Silicon ARM64.
  • .NET SDK 10.0.403 compiled the reproduction with Release configuration and target framework net10.0.
  • Installed ARM64 runtime 10.0.14
  • Official side-by-side ARM64 runtime 10.0.15, commit 8e0f8ed231.
  • Official side-by-side ARM64 runtime 11.0.0, commit 297acf930f.
  • Official side-by-side x64 runtime 10.0.15 under Rosetta on the same Mac.
  • The same compiled ManagedFields.dll was used across the runtime matrix. .NET 11 execution used DOTNET_ROLL_FORWARD=Major.
  • The side-by-side runtime archives came from Microsoft release-metadata URLs and were verified against the published SHA-512 hashes. The original installed runtime was left intact.
  • The attachment records download URLs, checksums, sanitized dotnet --info output, source hashes, assembly hashes, and every measured run.
  • This is a console application. No Blazor or browser runtime is involved.
  • Windows, Linux, other ARM64 CPUs, and native Intel/AMD hardware remain untested.

The tested ManagedFields.dll SHA-256 is

d6d791ebd3c5bda202b0b4326785e31b766671ef8483284a3235666af5d28f3d

Other information

The exact internal JIT optimization responsible has not been identified. The captured managed IL and generated machine code show a field-width mismatch at the array address calculation. Security impact beyond the process crash has not been assessed.

In the default Tier1 ARM64 version, the relevant instructions are

str     x1, [fp, #0x18]
ldr     x14, [x0, #0x08]
ldr     w15, [x14, #0x08]
cmp     w15, w1
bls     dictionary_fallback
ldr     w15, [x14, #0x08]
cmp     w1, w15
bhs     range_check_failure
add     x14, x14, #16
add     x14, x14, x1, lsl #3
mov     x15, x2
bl      CORINFO_HELP_ASSIGN_REF

The saved x1 contains both tuple fields, 0xffffffff000000a8. The comparisons use w1, which is 168, while the scaled address uses x1. The faulting helper instruction is stlr x15, [x14].

The IL for Commit reads the first Int32 field for both the bounds check and the array store

IL_0000 ldarg.1
IL_0001 ldfld Int32 Item1
IL_0006 ldarg.0
IL_0007 ldfld Value[] values
IL_000c ldlen
IL_000d conv.i4
IL_000e bge.un.s IL_001f
IL_0010 ldarg.0
IL_0011 ldfld Value[] values
IL_0016 ldarg.1
IL_0017 ldfld Int32 Item1
IL_001c ldarg.2
IL_001d stelem.ref
IL_001e ret
IL_001f ldarg.0
IL_0020 ldfld System.Collections.Generic.Dictionary`2[System.ValueTuple`2[System.Int32,System.Int32],Value] groups
IL_0025 ldarg.1
IL_0026 ldarg.2
IL_0027 callvirt Void set_Item(System.ValueTuple`2[System.Int32,System.Int32], Value)
IL_002c ret

The assembly references only System.Runtime, System.Collections, System.Memory, System.Console, and System.Threading.Thread.

The debugger stopped at PAL_DispatchExceptionInner and read the original ARM64 CONTEXT before the later fail-fast abort. The attachment includes that original fault context and the surrounding caller instructions.

This was initially observed in a managed simulation using (bool Independent, int Id). Its original captured fault had a valid 4096-element array, Id=168, Independent=false, and packed tuple register 0xffffff00000000a8. Its three padding bytes entered the same full-register index calculation. The original captured correct destination was 0x70004ad340 and the actual destination was 0xfffff870004ad340. A sanitized register/instruction excerpt is attached.

A supplementary (bool,int) control deliberately fills padding through MemoryMarshal.AsBytes while checking that the logical fields remain false and 168. That specific shape crashes on .NET 10.0.14/10.0.15 and passes on .NET 11.0.0. PGO-off and tiering-off also pass that particular padding shape. The primary ordinary (int,int) reproduction above is broader and crashes on all three ARM64 runtimes and settings. Their measurements are kept in separate evidence directories.

The ZIP includes the primary reproduction, the padding control, the separate-scalar control, the issue draft, IL, JIT disassembly, fault registers, runtime provenance, and detailed results. It contains source and text evidence, with local usernames redacted. The packaged primary source was rebuilt and its IL matched the tested assembly. The rebuilt version reproduced the ARM64 crash again on both .NET 10.0.15 and 11.0.0, and both zero-tag controls passed.

Archive SHA-256

90ae9b4b40dccfd235f78ce0ac0a4849c9c745d70ce3edebd8d1124510fcb626

Please investigate the field narrowing at the ARM64 index calculation and whether other ARM64 targets are affected.

dotnet-arm64-tuple-index-report-2026-11-24.zip

Activity

  1. added
    untriaged
    on Nov 24, 2026
  2. added
    area-CodeGen-coreclr
    on Nov 24, 2026
  3. dotnet-policy-service commented on Nov 24, 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. self-assigned this
    on Nov 24, 2026
  5. removed
    untriaged
    on Nov 24, 2026
  6. AndyAyersMS commented on Nov 24, 2026

    @AndyAyersMS
    Member

    Thanks for reporting this; investigating now. It might be fixed by #134466, which is only in main/12.0.

  7. AndyAyersMS commented on Nov 24, 2026

    @AndyAyersMS
    Member

    Update: it is fixed by #134466.

    @Hekinen93 can you say more about how this impacts your use of .NET, and in particular if a fix in .NET 11 would be sufficient?

  8. Hekinen93 commented on Nov 24, 2026

    @Hekinen93
    Author

    Hi.
    Yes , it crashed my simulation a couple of times on clients and 17 times today in my new unit testing pipeline.
    I have worked around it, now i am passing bool flag and int id separate for now until its fixed.
    Yes certainly .NET 11 is perfect i just need to update :).
    Thankyou for the fast response!

  9. added this to the 11.0.0 milestone on Nov 25, 2026
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