python / python/cpython

compression.zstd produces a broken archive if nothing is written

Offen
#155,286 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

3.15 3.16 extension-modules type-bug
Vorherrschende Sprache
Python
Sterne
77.2k
Forks
35.9k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit compression/zstd/_zstdfile.py und dem in compression/_common_streams.py gezeigten Leseweg. Reproduziere den Fall eines leeren Context-Managers und vergleiche ihn anschließend mit dem Fall eines leeren Schreibvorgangs und dem Verhalten von gzip. Erledigt ist die Aufgabe, wenn ein ohne Aufrufe von write() erstelltes Archiv erneut geöffnet und als leer gelesen werden kann und eine Regressionstestabdeckung hinzugefügt wurde; der verknüpfte PR gh-155342 zeigt, dass die Arbeit bereits begonnen hat.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
backend
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.