Skip to content

MemoryMappedFile (Windows): failed MEM_COMMIT is ignored, accessor over reserved memory crashes the process #136599

Description

@EgorBo

Description

MemoryMappedView.CreateView calls Interop.VirtualAlloc(..., MEM_COMMIT, ...) for DelayAllocatePages views but discards its return value. The following failure check tests viewHandle.IsInvalid (the already-valid map view handle) instead, so a failed commit is treated as success and the view is published over MEM_RESERVE pages.

Repro

Plain safe C#. The view is larger than the system commit limit.

using System.IO.MemoryMappedFiles;

using var mmf = MemoryMappedFile.CreateNew(null, 1L << 42, MemoryMappedFileAccess.ReadWrite,
    MemoryMappedFileOptions.DelayAllocatePages, HandleInheritability.None);
using var acc = mmf.CreateViewAccessor(0, 1L << 40);
Console.WriteLine("accessor created, capacity=" + acc.Capacity);
acc.Write(0, (byte)1);
Console.WriteLine("write succeeded");

Actual behavior

net11.0 RC2, win-x64 (64 GB RAM, commit limit ~103 GB). CreateViewAccessor succeeds, then an in-range write is a fatal AccessViolationException:

accessor created, capacity=1099511627776
Fatal error.

(1L << 36 = 64 GB views succeed on this machine, so it only reproduces above the commit limit.)

Expected behavior

CreateViewAccessor / CreateViewStream throws (e.g. IOException / Win32Exception for the commit failure). Safe accessor APIs never fault.

Notes

  • src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Windows.cs:62-70.
  • Fix: capture the VirtualAlloc result, and on failure dispose the view and throw with the last error.

Activity

  1. added
    untriaged
    on Oct 28, 2026
  2. dotnet-policy-service commented on Oct 28, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-io
    See info in area-owners.md if you want to be subscribed.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.IObuguntriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions