You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
compression.zstd produces a broken archive if nothing is written #155286
3.15bugs and security fixes3.16new features, bugs and security fixesextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error
Creating an empty zstd archive without any .write() calls produces a zero-byte file that fails to open later.
importcompression.zstdaszstdwithzstd.open("test.zst", "w") asf:
passwithzstd.open("test.zst", "r") asf:
f.read() # EOFError here. Won't happen if you just pass instead of readingTraceback (mostrecentcalllast):
File"<python-input-4>", line2, in<module>f.read()
~~~~~~^^File"compression\zstd\_zstdfile.py", line173, inreadFile"compression\_common\_streams.py", line118, inreadallFile"compression\_common\_streams.py", line99, inreadEOFError: Compressedfileendedbeforetheend-of-streammarkerwasreached
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.
changed the title [-]compression.zstd produces broken archive if nothing is written[/-][+]compression.zstd produces a broken archive if nothing is written[/+]on Aug 6, 2026
Zstandard compressed data is made up of one or more frames.
The structure of a single Zstandard frame is as follows: Magic_Number: 4 bytes, little-endian format. Value: 0xFD2FB528 ...
(and also roundtrips properly?)
It does in cli. Maybe it's more problematic in C, but that shouldn't be passed onto python user.
I see. I assume that since we never write anything, then we never actually write the frame and end up with a corrupted archive indeed. Thanks for confirming!
3.15bugs and security fixes3.16new features, bugs and security fixesextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error
Activity
[-]compression.zstd produces broken archive if nothing is written[/-][+]compression.zstd produces a broken archive if nothing is written[/+]picnixz commentedon Aug 6, 2026
OOC, does the reference zstd allow to produce an empty archive (and also roundtrips properly?)
mavriski commentedon Aug 6, 2026
Empty archives seem to be invalid: https://datatracker.ietf.org/doc/html/rfc8878#name-zstandard-frames
It does in cli. Maybe it's more problematic in C, but that shouldn't be passed onto python user.
It's not equivalent to python's write(b"") output, but it doesn't have to be.
picnixz commentedon Aug 6, 2026
I see. I assume that since we never write anything, then we never actually write the frame and end up with a corrupted archive indeed. Thanks for confirming!
pythongh-155286: Emit an empty frame for empty append paths
pythongh-155286: Test empty append paths and writable wrappers