Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#136,599 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp
Lĩnh vực
backend, operating-systems

Hướng nghiên cứu

Đọc src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Windows.cs, đặc biệt là các dòng 62–70, nơi VirtualAlloc commit các trang cho việc cấp phát trì hoãn. Kiểm tra cách mã gần đó báo lỗi cấp phát native và giải phóng view. Công việc hoàn tất khi commit thất bại khiến việc tạo view ném ngoại lệ thay vì trả về một accessor có thể gặp sự cố khi ghi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area-System.IO bug untriaged

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.
Ngôn ngữ chính
C#
Star
18.4k
Fork
5.8k
Merge trung bình
2 ngày 16 giờ
Pull request đã merge (30 ngày)
631

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của dotnet/runtime

Tất cả issue của dotnet/runtime

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.