-
-
Notifications
You must be signed in to change notification settings - Fork 433
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
CRC issue with deflate compression and a read loop #414
Comments
Does changing mz_strm_zlib.c at line 208 from:
To:
Solve the issue? |
No, but the issue disappears if I remove mz_strm_zlib.c:171 and mz_strm_zlib.c:172, where it doesn't continue to check
I'm testing to see if that is sufficient and doesn't break anything, though so far it looks like it is working. Do you think any other decompression libraries need a similar change? It seems reasonable that because they can decompress unpredictable amounts, they will have to have some internal mechanism to store it when it doesn't fit in the output. |
minizip probably uses |
I have made a similar change to the bzip and lzma streams in case the problem is also there. Thanks reporting and fixing. |
Thank you! |
I took another look at this. I'm not so sure |
Thank for the second look. The most important part of my PR was the removal of the I see now that you added the while loop clause but not the removal of the short circuit to the other method. The removal of the short circuit is the change that really fixed it. (In zlib, I didn't encounter truncated output in the other streams, but certainly could have missed it.) Good catch on |
With a particular output buffer, a zip file with an AES encrypted (this may be red herring) and zlib compressed item fails reading with a CRC error. I noticed it with a buffer size of 8192 and a uncompressed item of size 7077903, but I saw it at some other combinations.
On investigation, it appears that zlib::inflate may read data from the input buffer and/or write it to the output buffer, but not neccessarily both. "If inflate returns Z_OK and with zero avail_out, it must be called again after making room in the output buffer because there might be more output pending." This means: zlib may consume X bytes, decompress them to an internal buffer, and then output the decompressed results over multiple calls. In the current implementation of
mz_strm_zlib
, the decompress loop will be escaped if there is no data to read and the minizip controlled buffer is empty, though there may be more data to output.main.cpp.zip is a test script that shows the problem.
Tested against minizip 2.8.9 (also 2.8.1) with
The text was updated successfully, but these errors were encountered: