Improper sanitization and documentation for `ZipFile.mkdir(mode)`
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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