python / python/cpython

zipfile.ZipFile fails to read zstd-compressed file consisting of multiple frames

Aperta
#154,481 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

stdlib type-bug
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Il reproducer usa zipfile.ZipFile.open e z.open sull’archivio allegato; inizia riproducendo il caso zstd a due frame nell’implementazione di zipfile di CPython. Il lavoro è completato quando la lettura di data.npy restituisce entrambi i frame e il normale controllo CRC ha esito positivo, con un test di regressione che copra questo comportamento.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.