zipfile.ZipFile fails to read zstd-compressed file consisting of multiple frames
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
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
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
O reproducer usa zipfile.ZipFile.open e z.open no arquivo anexado; comece reproduzindo o caso zstd de dois frames na implementação de zipfile do CPython. Considera-se concluído quando a leitura de data.npy retorna ambos os frames e a verificação normal de CRC é bem-sucedida, com um teste de regressão cobrindo esse comportamento.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- tooling
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 35/100