`ZipFile.testzip()` Skips Earlier Duplicate Members
まだ誰も着手していません。
評価
調査の方向性
ZipFile.testzip から始め、現在のエントリオープン動作を、issue にある重複メンバーの reproducer と比較します。reproducer と関連する zipfile テストを実行します。完了とは、すべての ZipInfo が個別にチェックされ、先にある破損した重複が duplicate.txt として報告されることを意味します。
索引モデルが issue の本文から書いたものです。
説明
Bug report
Summary
ZipFile.testzip() can incorrectly report that an archive is valid when an earlier member is corrupt and a later member has the same filename. The method iterates over all ZipInfo objects, but opens each one by filename instead of by its ZipInfo instance. Filename lookup selects the last duplicate, so earlier duplicates are checked against the wrong archive entry.
Minimal Reproducer
import io
import struct
import zipfile
buffer = io.BytesIO()
with zipfile.ZipFile(buffer, "w") as zf:
zf.writestr("duplicate.txt", b"corrupt me")
zf.writestr("duplicate.txt", b"valid data")
raw = bytearray(buffer.getvalue())
# Corrupt the payload of the first duplicate only.
with zipfile.ZipFile(io.BytesIO(raw)) as zf:
first = zf.infolist()[0]
name_length, extra_length = struct.unpack_from(
"<HH", raw, first.header_offset + 26
)
data_offset = (
first.header_offset + zipfile.sizeFileHeader +
name_length + extra_length
)
raw[data_offset] ^= 1
with zipfile.ZipFile(io.BytesIO(raw)) as zf:
first = zf.infolist()[0]
try:
zf.read(first)
except zipfile.BadZipFile:
print("The first duplicate is corrupt")
print(zf.testzip())
Observed output:
The first duplicate is corrupt
None
testzip() should return "duplicate.txt".
Expected Behavior
Every member in infolist() should be validated individually. For duplicate names, testzip() should preserve the identity of each ZipInfo object and open the entry with:
self.open(zinfo, "r")
Rather than:
self.open(zinfo.filename, "r")
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-156540
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 558
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
docs pending
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
build type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
stdlib topic-email type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
-
🐛 Bug 🔔 Pending processing
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
jumpserver/jumpserver#17584 ·