Windows `File::set_permissions` silently does nothing when clearing `readonly` leaves `FileAttributes == 0`
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 62/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- rust
调研方向
该缺陷位于 library/std/src/sys/fs/windows.rs 中的 File::set_permissions,它将 perm.attrs 直接传给 SetFileInformationByHandle 所用的 FILE_BASIC_INFO。请在 Windows 上使用 issue 中的概念验证代码复现,调用后 attrs: 1 应变为 attrs: 128。当通过文件句柄清除只读属性的文件最终具有 FILE_ATTRIBUTE_NORMAL 且 readonly=false 时,即视为完成。请先查看已关闭且未合并的 pull request #165701,了解它未被合入的原因。
由索引模型根据 Issue 内容生成。
描述
Summary
On Windows, calling File::set_permissions with perm.set_readonly(false) returns Ok(()) without clearing the read-only attribute whenever FILE_ATTRIBUTE_READONLY (0x1) is the file's only attribute. By contrast, path-based fs::set_permissions with the same Permissions value clears the read-only attribute as expected.
Root Cause
In library/std/src/sys/fs/windows.rs, File::set_permissions passes perm.attrs directly to SetFileInformationByHandle via FILE_BASIC_INFO. Per the FILE_BASIC_INFO documentation for FileAttributes:
If this is set to 0 in a FILE_BASIC_INFO structure passed to SetFileInformationByHandle then none of the attributes are changed.
To clear all attributes on a file, callers must instead pass FILE_ATTRIBUTE_NORMAL (0x80)
Suggested Fix
In File::set_permissions (library/std/src/sys/fs/windows.rs), normalize 0 to c::FILE_ATTRIBUTE_NORMAL (0x80), matching SetFileAttributesW:
FileAttributes: if perm.attrs == 0 { c::FILE_ATTRIBUTE_NORMAL } else { perm.attrs },
Reporting on behalf of Microsoft FORGE Lab. Initially discovered by an AI agent.
- 主要语言
- Rust
- 星标
- 121k
- 派生
- 17.3k
- 平均合并
- 2 天 16 小时
- 30 天内合并 PR
- 529
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rust-lang/rust 的其他 Issue
-
A-run-make relnotes relnotes-needs-review relnotes-tracking-issue T-lang T-libs
难度 1/5 1 小时以内 新手友好度 72/100
维护者通常 1 天内回复
-
relnotes relnotes-needs-review relnotes-tracking-issue T-compiler T-libs
难度 1/5 1 小时以内 新手友好度 78/100
维护者通常 1 天内回复
-
A-LLVM O-Arm O-UEFI O-x86_64 relnotes relnotes-needs-review relnotes-tracking-issue T-compiler
难度 1/5 1 小时以内 新手友好度 72/100
rust-lang/rust#165504 · 1 条评论 ·
维护者通常 1 天内回复
-
relnotes relnotes-tracking-issue T-libs
难度 1/5 1 小时以内 新手友好度 72/100
维护者通常 1 天内回复
-
unclear wording in vec macro可能已有人在做 @Suhird 于 7 天前认领。 未关闭A-docs A-slice-vec T-libs
难度 1/5 1-3 小时 新手友好度 70/100
rust-lang/rust#165360 · 6 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
相似的 Issue
-
SPLADE `/embed_sparse` output depends on the other inputs in the batch (candle BertModel / DistilBertModel)可能已有人在做 @0z5a 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
huggingface/text-embeddings-inference#979 ·
维护者通常 1 天内回复
-
good first issue help wanted
难度 2/5 1-3 小时 新手友好度 78/100
servo/rust-smallvec#874 ·
-
难度 1/5 1 小时以内 新手友好度 94/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 2 天内回复
-
ci enhancement need-triage
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复