python / python/cpython

compression.zstd produces a broken archive if nothing is written

Aperta
#155,286 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

3.15 3.16 extension-modules 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:

Creating an empty zstd archive without any .write() calls produces a zero-byte file that fails to open later.

import compression.zstd as zstd
with zstd.open("test.zst", "w") as f:
    pass

with zstd.open("test.zst", "r") as f:
    f.read() # EOFError here. Won't happen if you just pass instead of reading

Traceback (most recent call last):
  File "<python-input-4>", line 2, in <module>
    f.read()
    ~~~~~~^^
  File "compression\zstd\_zstdfile.py", line 173, in read
  File "compression\_common\_streams.py", line 118, in readall
  File "compression\_common\_streams.py", line 99, in read
EOFError: Compressed file ended before the end-of-stream marker was reached

Reference Zstandard v.1.5.7 also won't open the resulting empty file:

zstd.exe -d test.zst -o aa.txt
zstd: test.zst: unexpected end of file

stat test.zst
  File: test.zst
  Size: 0               Blocks: 0          IO Block: 65536  regular empty file

Under same circumstances compression.gzip produces a proper non-empty gzip file that can decompresses into an empty string, which would probably be a desirable behaviour. In the current compression.zstd, you can have that by calling write(b"") instead of pass.

Tested on Windows with recent 3.15rc and 3.14 builds as well as on Linux with 3.10 via backports.zstd.

Python 3.15.0rc1 (tags/v3.15.0rc1:37e98da, Aug  4 2026, 11:37:18) [MSC v.1951 64 bit (AMD64)] on win32
Python 3.14.7 (tags/v3.14.7:823f032, Aug  5 2026, 10:51:32) [MSC v.1944 64 bit (AMD64)] on win32
Python 3.10.12 (main, Jun 22 2026, 18:55:27) [GCC 11.4.0] on linux  

Devguide suggested tagging @emmatyping for .zstd bugs.

CPython versions tested on:

3.15, 3.14, 3.10

Operating systems tested on:

Windows, Linux

Linked PRs
  • gh-155342

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

Inizia da compression/zstd/_zstdfile.py e dal percorso di lettura mostrato in compression/_common_streams.py. Riproduci il caso del context manager vuoto, quindi confrontalo con il caso di una scrittura vuota e con il comportamento di gzip. Il lavoro è completato quando un archivio creato senza chiamate a write() può essere riaperto e letto come vuoto, con l’aggiunta della copertura di regressione; il PR collegato gh-155342 indica che il lavoro è già in corso.

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

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.