zipfile.ZipFile fails to read zstd-compressed file consisting of multiple frames
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
I have a ZIP file archive.zip that contains a file data.npy. This file is compressed with zstd, consisting of two zstd frames. When I try to read this in with zipfile, I get a BadZipFile: Bad CRC-32 for file 'data.npy' error.
import zipfile
with zipfile.ZipFile("archive.zip", "r") as z:
with z.open("data.npy", "r") as f:
data = f.read() # -> BadZipFile: Bad CRC-32 ...
The error is a red herring, though: When I disable CRC checking, there is no exception thrown, but the data read is in fact only the data from the first zstd frame. The second frame gets ignored completely (and thus the checksum is wrong).
import zipfile
with zipfile.ZipFile("archive.zip", "r") as z:
with z.open("data.npy", "r") as f:
f._update_crc = lambda newdata: None
data = f.read() # -> result only contains data from first frame
As independent cross-check, I tested decompressing the file with both 7z and WinRAR without issues. So I don't think the file is somehow invalid. This is the file: archive.zip
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Linked PRs
- gh-154537
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
复现程序在附加的归档文件上使用 zipfile.ZipFile.open 和 z.open;首先在 CPython 的 zipfile 实现中复现包含两个帧的 zstd 情况。完成的标准是读取 data.npy 返回两个帧,并且正常的 CRC 检查成功,同时有一个覆盖该行为的回归测试。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- tooling
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100