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
Error decompressing valid zlib data #52918
Comments
I have a valid zlib compressed string, attached here as 'mat.bin' (1.7M), that cause and error on zlib.decompress decompression: >>> import zlib
>>> data = open('mat.bin', 'rb').read()
>>> out = zlib.decompress(data)
Traceback (most recent call last):
File "<ipython console>", line 1, in <module>
error: Error -5 while decompressing data I know these data are valid, because I get the string I was expecting with:
As expected, there is no remaining data after this read:
I believe that the behavior of zlib.decompress(data) and zlib.decompressobj().decompress(data) should be equivalent, and that the error for zlib.decompress(data) is therefore the symptom of a bug. |
After a bit of debugging, it seems your data is not actually a complete zlib stream (*). What did you generate it with? (*) in technical terms, the zlib never returns Z_STREAM_END when decompressing your data. The decompressobj ignores it, but the top-level decompress() function considers it an error. |
Hi,
Thanks for the debugging. The stream comes from within a matlab 'mat' Is there (should there be) a safe and maintained way to allow me to |
So this would be a Matlab issue, right?
Decompressor objects allow you to do that, but I cannot tell you how |
I also think we should improve the zlib module's error messages. I've added a patch in bpo-8681 for that. With that patch, the message you'd've encountered would have been "Error -5 while decompressing data: incomplete or truncated stream", which is quite more informative. |
Yes, except scipy and numpy aim in part to be an open-source
This is the only .mat file stream I have yet come across that causes |
Ok, it turned out to be quite easy indeed. Here is a patch adding a test. |
patch looks good. |
The patch was committed in r81094 (2.7), r81095 (2.6), r81096 (3.2) and r81097 (3.1). Thank you! |
Note: 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: