Repository navigation
gh-160000: Fix LZMADecompressor raising on repeated empty decompress calls - #160205
Open
bunnysayzz wants to merge 1 commit into
Open
bunnysayzz wants to merge 1 commit into
bunnysayzz wants to merge 1 commit into
Conversation
|
The following commit authors need to sign the Contributor License Agreement: |
pganssle
reviewed
Oct 22, 2026
| lzd = LZMADecompressor() | ||
| for _ in range(3): | ||
| self.assertEqual(lzd.decompress(b'', max_length=0), b'') | ||
| # Same after real input: one byte out, then empty calls, |
Member
There was a problem hiding this comment.
I think this can be split into separate tests or parameterized in some way.
emmatyping
reviewed
Oct 23, 2026
Comment on lines
+962
to
964
| if (lzret == LZMA_BUF_ERROR && | ||
| (lzs->avail_in == 0 || lzs->avail_out == 0)) { | ||
| lzret = LZMA_OK; /* That wasn't a real error */ |
Member
There was a problem hiding this comment.
Rather than ignoring the error, we should add the input bytes to the input buffer, then return empty bytes without calling the library.
emmatyping
reviewed
Oct 23, 2026
Comment on lines
+1
to
+2
| Fix :class:`lzma.LZMADecompressor` raising :exc:`LZMAError` on repeated | ||
| ``decompress(b'', max_length=0)`` calls. |
Member
There was a problem hiding this comment.
Suggested change
| Fix :class:`lzma.LZMADecompressor` raising :exc:`LZMAError` on repeated | |
| ``decompress(b'', max_length=0)`` calls. | |
| Fix :class:`lzma.LZMADecompressor` raising :exc:`LZMAError` on repeated | |
| ``decompress()`` calls with ``max_length=0``. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #160000.
LZMADecompressor.decompress(b'', max_length=0)works once, then raisesLZMAError: Insufficient buffer spaceon the second call. Same after real input when output is pending internally.In
Modules/_lzmamodule.c,decompress_buftreatsLZMA_BUF_ERRORfrom liblzma as benign only whenavail_in == 0andavail_out > 0. Withmax_length=0there is no output space, so that check never fires for the empty call, and the error escapes. The fix treats it as benign whenavail_in == 0oravail_out == 0. That is safe because theavail_out == 0branch either breaks once the requested length is reached or grows the buffer, so it cannot spin.Also adds a regression test in
Lib/test/test_lzma.pycovering the empty case and the after-real-input case, and a NEWS entry.Verified by building CPython from main and running the test suite:
test_lzmapasses (125 tests), the issue repro returnsb''on repeated calls, the decompressor stays usable afterwards, and corrupt input still raisesLZMAError.Note: this is my first CPython PR, I will complete the CLA check when prompted.
LZMADecompressor.decompress(b'', max_length=0)raisesLZMAErroron the second consecutive call #160000