Improper sanitization and documentation for `ZipFile.mkdir(mode)`
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 36k
- PR 合併指標
- PR 指標待擷取
描述
Bug report
Bug description:
When calling ZipFile.mkdir(), the user provided mode does not have the file format bits cleared, which may cause the created entry be recognized as an incorrect or unknown file format.
import io
import stat
import zipfile
with zipfile.ZipFile(io.BytesIO(), 'w') as zh:
zh.mkdir('foo/', 0o107777) # regular file
zinfo = zh.getinfo('foo/')
print(oct(stat.S_IFMT(zinfo.external_attr >> 16))) # 0o140000 (socket file)
with zipfile.ZipFile(io.BytesIO(), 'w') as zh:
zh.mkdir('foo/', 0o127777) # symbolic link
zinfo = zh.getinfo('foo/')
print(oct(stat.S_IFMT(zinfo.external_attr >> 16))) # 0o160000 (unknown)
Additionally, the current source code and doc for ZipFile.mkdir()'s default mode value are 511, which is identical to 0o777 but less intuitive.
Suggestion
Instead of the current sanitization:
zinfo.external_attr = ((0o40000 | mode) & 0xFFFF) << 16
we should probably sanitize the provided mode as what stat.S_IMODE does, i.e.:
zinfo.external_attr = (0o40000 | (mode & 0o7777)) << 16
We should probably also revise the source code and doc for ZipFile.mkdir()'s default mode value to 0o777, to be consistent with os.mkdir() and more intuitive.
CPython versions tested on:
3.14
Operating systems tested on:
No response
Linked PRs
- gh-154509
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 ZipFile.mkdir() 進入點開始,檢查 mode 如何被清理為 external_attr,以及文件中記錄的預設值。將其行為與 stat.S_IMODE 和 os.mkdir() 進行比較;完成標準是排除檔案類型位元,並將預設值顯示為 0o777,同時檢查已連結的 PR gh-154509,了解已在進行中的工作。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- operating-systems
- Issue 類型
- 缺陷
- 難度
- 2/5
- 預估耗時
- 1-3 小時
- 活躍度
- 停滯
- 描述清晰度
- 描述清楚
- 新手友好度
- 25/100