Windows `File::set_permissions` silently does nothing when clearing `readonly` leaves `FileAttributes == 0`

未关闭 适合新手
#165,696 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@ChrisDenton 已经在做这个了。

开始于 2026年11月10日。

  • #165701 来自 @lazerg —— 已关闭,未合并
  • #165734 来自 @ChrisDenton —— 未关闭

评估

难度
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 内容生成。

描述

A-filesystem C-bug O-windows T-libs

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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rust-lang/rust 的其他 Issue

查看 rust-lang/rust 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。