-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
LZMACompressor and LZMADecompressor raise exceptions if given empty strings twice #71704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
To reproduce: >>> import lzma
>>> c = lzma.LZMACompressor()
>>> c.compress(b'')
b'\xfd7zXZ\x00\x00\x04\xe6\xd6\xb4F'
>>> c.compress(b'')
b''
>>> c.compress(b'')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_lzma.LZMAError: Insufficient buffer space
>>> d = lzma.LZMADecompressor()
>>> d.decompress(b'')
b''
>>> d.decompress(b'')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_lzma.LZMAError: Insufficient buffer space This can occur anytime during compression/decompression when an empty string is passed twice in a row. The problem is that that liblzma interprets a call to lzma_code() with avail_in == 0 as a buffer full condition. The second time in a row it encounters this, it returns LZMA_BUF_ERROR as per documentation. The attached patch prevents this condition from occurring. |
Why you passing decompress without passing compress before decompressing it again? Also I would expect that it would show the same compress result trice in a row on the 1st test. This must definately be a issue. |
The above code demonstrates two separate issues. One with the decompressor, and one with the compressor. In the compressor example, the first output differs from the rest because it is a file header which is always emitted. That behavior is correct. |
Thank you for your report and patch Benjamin. Seems your patch fixes the problem in default case. But the compressor still fails with the raw format. >>> import lzma
>>> FILTERS_RAW_4 = [{"id": lzma.FILTER_DELTA, "dist": 4},
... {"id": lzma.FILTER_X86, "start_offset": 0x40},
... {"id": lzma.FILTER_LZMA2, "preset": 4, "lc": 2}]
>>> c = lzma.LZMACompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_4)
>>> c.compress(b'')
b''
>>> c.compress(b'')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_lzma.LZMAError: Insufficient buffer space |
Ah, thank you. Good catch. I have reworked the patch to handle both cases. |
New changeset b06f15507978 by Serhiy Storchaka in branch '3.5': New changeset fb64c7a81010 by Serhiy Storchaka in branch '3.6': New changeset 98c078fca8e0 by Serhiy Storchaka in branch 'default': |
Thank you for you contribution Benjamin. |
Misc/NEWS
so that it is managed by towncrier #552Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: