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
LZMADecompressor.decompress(b'', max_length=0) raises LZMAError on the second consecutive call #160000
BZ2Decompressor, zlib._ZlibDecompressor and ZstdDecompressor all return b'' for any number of such calls, and the decompressor stays usable. The same happens after real input, e.g. decompress(stream, 1) followed by two decompress(b'', 0) calls.
max_length=0 is a legitimate request ("just buffer this, don't produce output yet"), so I would expect b'' and no error.
The mechanism, as far as I can tell: liblzma returns LZMA_BUF_ERROR when two consecutive lzma_code calls can make no progress (no input consumed, no output produced). decompress_buf already treats that as benign, but only when there is output space available: Modules/_lzmamodule.c lines 962-964. With max_length=0 the output buffer has zero bytes, so avail_out > 0 is false and the error goes to catch_lzma_error, which maps it to "Insufficient buffer space" (Modules/_lzmamodule.c lines 169-171). Dropping the avail_out > 0 condition when avail_in == 0 is probably enough; zlibmodule.c tolerates Z_BUF_ERROR unconditionally in the equivalent loop.
Found by the Hypothesis tests in #159960, which record it as LZMADecompressorTests.test_repeated_max_length_zero under expectedFailure. Those tests also leave max_length=0 out of the broader lzma strategies for now so that the other properties keep running; that carve-out can go once this is fixed.
Root cause is in Modules/_lzmamodule.c, in decompress_buf. liblzma returns LZMA_BUF_ERROR when two consecutive lzma_code calls make no progress, and the code only treats that as benign when avail_in == 0 and avail_out > 0. With max_length=0 there is no output space, so the second call raises instead of returning b'', and the same happens after real input when output is pending internally and avail_out is 0.
Fix widens the benign check to avail_in == 0 or avail_out == 0. That is safe because the avail_out == 0 branch either breaks once the requested length is reached or grows the buffer. Added a regression test in Lib/test/test_lzma.py for both the empty case and the after-real-input case, plus a NEWS entry. Opening the fix PR right after this comment.
Activity
Add a pinned test for max_length=0 calls with output pending
bunnysayzz commentedon Oct 22, 2026
Root cause is in Modules/_lzmamodule.c, in decompress_buf. liblzma returns LZMA_BUF_ERROR when two consecutive lzma_code calls make no progress, and the code only treats that as benign when avail_in == 0 and avail_out > 0. With max_length=0 there is no output space, so the second call raises instead of returning b'', and the same happens after real input when output is pending internally and avail_out is 0.
Fix widens the benign check to avail_in == 0 or avail_out == 0. That is safe because the avail_out == 0 branch either breaks once the requested length is reached or grows the buffer. Added a regression test in Lib/test/test_lzma.py for both the empty case and the after-real-input case, plus a NEWS entry. Opening the fix PR right after this comment.