MemoryMappedFile (Windows): failed MEM_COMMIT is ignored, accessor over reserved memory crashes the process
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- csharp
调研方向
阅读 src/libraries/System.IO.MemoryMappedFiles/src/System/IO/MemoryMappedFiles/MemoryMappedView.Windows.cs,尤其是第 62–70 行,其中 VirtualAlloc 为延迟分配提交页面。检查附近的代码如何报告 native 分配失败并释放视图。完成标准是:提交失败时,视图创建会抛出异常,而不是返回一个可能在写入时崩溃的 accessor。
由索引模型根据 Issue 内容生成。
描述
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
VirtualAllocresult, and on failure dispose the view and throw with the last error.
- 主要语言
- C#
- 星标
- 18.4k
- 派生
- 5.8k
- 平均合并
- 2 天 15 小时
- 30 天内合并 PR
- 620
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
dotnet/runtime 的其他 Issue
-
[wasi] .NET 10: WasmEnableSIMD with AOT fails because WasiApp.targets has -msimd128 commented out未关闭area-Build-mono untriaged
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
area-System.ComponentModel untriaged
难度 2/5 1-3 小时 新手友好度 65/100
dotnet/runtime#136608 · 2 条评论 ·
维护者通常 1 天内回复
-
area-System.IO untriaged
难度 2/5 1-3 小时 新手友好度 76/100
dotnet/runtime#136577 · 1 条评论 ·
维护者通常 1 天内回复
-
[mono] Native memory leak on the first invoke of every open-instance delegate to a virtual method未关闭area-VM-meta-mono untriaged
难度 2/5 1-3 小时 新手友好度 72/100
dotnet/runtime#136284 · 6 个 reaction ·
维护者通常 1 天内回复
-
Several MemoryExtensions.LastIndexOfAnyExcept overloads incorrectly document "first occurrence"可能重新可做 @ehsan-raoufi 于 8 天前认领,目前没有进行中的 PR。 未关闭area-System.Memory untriaged
难度 1/5 1 小时以内 新手友好度 83/100
dotnet/runtime#136282 · 1 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
[Format]: .dart未关闭formats
难度 2/5 1-3 小时 新手友好度 62/100
KnifeLemon/Filee#980 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
bug effort:S P3
难度 2/5 1-3 小时 新手友好度 72/100
nightscout/nocturne#3219 ·
维护者通常 1 天内回复
-
good first issue
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复