-
Notifications
You must be signed in to change notification settings - Fork 339
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
Inconsistent behaviour between miniz and zlib in inflate #80
Comments
I have encountered a related issue, miniz can enter a state where Although the official zlib documentation does say This was worked around by checking for unexpected return values up front before checking the value of |
Testing miniz with unshield I see some tests fail because of inconsistencies between miniz and zlib inflate |
Guys you know what's going on and how to fix it, could you produce a patch to fix this miniz bug? |
I do not know how to fix this within miniz, only how to workaround it as a client of miniz (as described in my initial post). |
Thanks @drglove for providing I created an automated test procedure for linux (and unix) systems that includes miniz.c/h. Just run Challenge: fix
log files:
miniz: as we can see, at some point both --- zlib.log 2021-05-14 12:06:28.000000000 +0800
+++ miniz.log 2021-05-14 12:06:29.000000000 +0800
@@ -44,17 +44,17 @@
total_in: 4718592
total_out: 15218849
[10]
-avail_in: 10636
+avail_in: 5913
avail_out: 0
-total_in: 5232244
+total_in: 5236967
total_out: 17316001
[11]
-avail_in: 0
-avail_out: 2053873
-total_in: 5242880
-total_out: 17359280
+avail_in: 5913
+avail_out: 2078881
+total_in: 5236967
+total_out: 17334272
[12]
avail_in: 0
-avail_out: 947632
-total_in: 5527204
-total_out: 18508800
+avail_out: 947639
+total_in: 5521291
+total_out: 18483785 |
If
inflate
returnsZ_OK
orZ_BUF_ERROR
, andavail_out
is not zero, thenavail_in
must be guaranteed to be zero. I have some data I compressed withdeflate
usingminiz
that, when trying to inflate it, does not follow this. This guarantee was confirmed by Mark Adler himself in this Stack Overflow post.I have enabled the following preprocessor defines in
miniz.h
:MINIZ_NO_STDIO
MINIZ_NO_TIME
MINIZ_NO_ARCHIVE_APIS
MINIZ_NO_ARCHIVE_WRITING_APIS
My inflate and deflate loop are copied directly from the
zpipe.c
example inzlib
, with the only difference being that I use a 512KB input buffer for reading from disk, and a 2MB output buffer for inflated data to be written to disk. This includes usingZ_NO_FLUSH
. I've included my source for testing and the deflated data that I am trying to inflate. Note thatzlib
inflates this fine.zlib-test.zip
It seems to me that in
mz_inflate
, ifm_dict_avail
on the stream is non-zero, thenavail_in
is not being properly updated, oravail_out
is being incorrectly updated. This might be a naive picture though. It is strange though thatavail_out
is updated there, butavail_in
is not. The result is that one of the calls toinflate
near the stream end,avail_out
is non-zero, andavail_in
is also non-zero.Changing the termination condition of the inner do-while loop from
avail_out == 0
(the one recommended byzlib
) toavail_out == 0 || avail_in > 0
successfully decompresses the stream. It appears that callinginflate
again after the stream has gotten into such a state is safe, at least with my data stream.The text was updated successfully, but these errors were encountered: