FileStatus.IsModeReadOnlyCore compares group with user where its comment says other: an extra getgroups per entry, and a wrong ReadOnly for some modes
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- csharp, macos
调研方向
阅读 src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.Unix.cs 中 IsModeReadOnlyCore 附近的代码,尤其是权限比较及其注释。检查现有的 Unix 文件权限处理测试,然后补充测试,覆盖组权限与其他用户权限一致的情况,以及其他用户拥有的文件处于模式 0446 的情况。完成标准是比较逻辑符合注释,并且错误的只读结果和不必要的组查询都得到解决。
由索引模型根据 Issue 内容生成。
描述
Description
FileStatus.IsModeReadOnlyCore (Unix) skips the group check when group and user agree, where its comment speaks of group and other:
// System files often have the same permissions for group and other (umask 022).
if (isGroupReadOnly == isUserReadOnly)
{
return isGroupReadOnly;
}
This has two effects for a file or folder another user owns:
- Speed. For the common 0755 or 0644 owned by root, group and other agree (both read-only) but user and group don't, so the shortcut is missed and
IsMemberOfGroupruns. On macOS that callsgetgroups, which asks opendirectoryd and takes about a millisecond each time. ReadingFileSystemInfo.AttributesorFileSystemEntry.Attributesover a tree another user owns pays it for every entry. Walking the 1,163 folders of/usr/local/share/dotnet/packs(root-owned, as the macOS installer leaves it) and reading each one's attributes took 644 ms cold and 274 ms warm. Telling links apart there withLinkTargettook 34 ms. - Correctness. Where group and user agree but other differs, a caller who is neither the owner nor in the group gets the group's answer instead of other's. For example, mode 0446 owned by another user reports
ReadOnlyto someone outside the group, who may write it.
Reproduction Steps
On macOS, as a user other than root:
var watch = System.Diagnostics.Stopwatch.StartNew();
int count = 0;
foreach (string folder in Directory.EnumerateDirectories("/usr/local/share/dotnet/packs", "*", SearchOption.AllDirectories))
{
_ = new DirectoryInfo(folder).Attributes;
count++;
}
Console.WriteLine($"{count} folders, {watch.ElapsedMilliseconds} ms");
Expected behavior
The group check is skipped when group and other agree, as the comment says. Folders owned by root with mode 0755 then need no getgroups call.
Actual behavior
Every such folder calls IsMemberOfGroup. For mode 0446 owned by another user, a caller outside the group is told the file is read-only.
Regression?
Not known.
Known Workarounds
Avoid reading Attributes where only a link check is needed, for example with LinkTarget.
Configuration
.NET 11.0.0, macOS 27 on ARM64 (Apple M2 Max). The code is the same on main.
Other information
The likely fix is if (isGroupReadOnly == isOtherReadOnly).
- 主要语言
- C#
- 星标
- 18.5k
- 派生
- 5.8k
- 平均合并
- 2 天 8 小时
- 30 天内合并 PR
- 597
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
dotnet/runtime 的其他 Issue
-
area-VM-meta-mono untriaged
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
area-Debugger-mono untriaged
难度 2/5 1-3 小时 新手友好度 75/100
dotnet/runtime#138494 · 1 条评论 ·
维护者通常 1 天内回复
-
area-AssemblyLoader-mono untriaged
难度 2/5 1-3 小时 新手友好度 78/100
dotnet/runtime#138493 · 1 条评论 ·
维护者通常 1 天内回复
-
JsonConsoleFormatter throws on NaN and infinite double and float values, failing the log call可能已有人在做 @Mohamedadel-prog 于 1 天前认领。 未关闭area-Extensions-Logging untriaged
难度 2/5 1-3 小时 新手友好度 82/100
dotnet/runtime#138418 · 2 条评论 ·
维护者通常 1 天内回复
-
area-Codegen-AOT-mono untriaged
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
microsoft/sqltoolsservice#2851 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
needs-triage
难度 2/5 1-3 小时 新手友好度 83/100
elsa-workflows/elsa-foundation#6322 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 74/100
mohebifar/made-in-iran#273 ·
-
Test bug: Include_collection_with_cross_apply_with_filter relies on nondeterministic ORDER BY with Take可能已有人在做 @Mohamedadel-prog 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 2 天内回复