zipfile.ZipFile fails to read zstd-compressed file consisting of multiple frames
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Mã tái hiện sử dụng zipfile.ZipFile.open và z.open trên kho lưu trữ đính kèm; hãy bắt đầu bằng cách tái hiện trường hợp zstd gồm hai frame trong phần triển khai zipfile của CPython. Công việc được xem là hoàn tất khi việc đọc data.npy trả về cả hai frame và kiểm tra CRC thông thường thành công, với một bài kiểm thử hồi quy bao quát hành vi này.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- tooling
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100