zipfile should reject inconsistent disk information in EOCDR
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
zipfile is explicitly documented as not handling multipart (i.e. multi-disk) ZIPs.
However, zipfile also does not check the EOCDR's state for consistency with that invariant.
Two fields are relevant (offsets are relative to the start of the EOCDR):
- "number of this disk" (offset 4, size 2)
- "number of the disk with the start of the central directory" (offset 6, size 2)
In zipfile's model, both of these should always be 0, since there's exactly one "disk."
However, at the moment, zipfile appears to silently ignore these fields and allows a parse even when they're incoherent or inconsistent with each other. For example:
import io
import struct
import zipfile
archive = io.BytesIO()
with zipfile.ZipFile(archive, "w") as zipf:
zipf.writestr("entry.txt", b"payload")
data = bytearray(archive.getvalue())
eocd = data.rfind(zipfile.stringEndArchive)
struct.pack_into("<H", data, eocd + 4, 1)
with zipfile.ZipFile(io.BytesIO(data)) as zipf:
print(zipf.namelist())
This exposes ['entry.txt'], whereas other parsers (Rust's zip and async_zip, Info-ZIP, and 7-ZIP) reject the ZIP as malformed.
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-155814
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、issue の BytesIO の例を再現し、zipfile の EOCDR 解析を追跡します。その際、オフセット 4 と 6 にある 2 つのディスク番号フィールドに注目してください。非ゼロまたは矛盾したディスク情報を持つ不正なアーカイブが正常に解析されるのではなく拒否されれば完了です。issue では進行中の作業として PR gh-155814 にリンクしています。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100