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
zng_deflateInit2 silently converts windowBits=8 to windowBits=9 #1449
Comments
Current zlib-ng behavior appears to be the same as madler/zlib. |
Perhaps inflate should also convert |
I found this bug report on Mark Adler's zlib from 2015: madler/zlib#94
Mark Adler explicitly chose not to do this apparently. This is a known bug. Best to leave it as is, and document it, I guess? |
I wonder whether we still have the 256-byte window bug in our deflate code or not, a lot of the involved code has been changed. |
I'm currently working on code that limits maximum size of the matches... It can be adapted for 256 byte windows to limit maximum match size to for example 130 bytes, but this means adding new function that only compare the last 128 bytes instead of last 256 bytes. |
@mtl1979 were you able to get anywhere with the 256 byte window issue? |
I haven't had much time to work on the patch as I've been working on other things and there has been quite big changes in the code, so I wanted to wait until the codebase is more stable. Basically we need to reduce |
Could an alternative be to hijack check_match or something similar to just truncate any found matches that were too long? Also, we could change zlib-ng native api to require windowBits minimum of 9 for both deflate and inflate (with a documented and silent conversion of 8 -> 9 to avoid older applications getting into trouble), I have a feeling that is a worthwhile tradeoff. The zlib-compat codepath could still benefit from a fix of some kind of course. Personally, I don't see a problem with just using windowBits = 9 there too (The only downside is a miniscule extra amount of ram, right?), but I am open to better solutions as long as they are not too intrusive. |
zlib-ng can't handle windowBits=8. This is fine. What is not fine is that instead of crashing it starts deflating with windowBits=9. As a result when inflating again with windowBits=8 it crashes with an invalid window size. This crash occurs to late. If zng_deflateInit2 finds that the data cannot be deflated using the user-requested settings it should crash right away and notify the user of this problem. Verbosely crashing is better than silently subverting user expectations and then mysteriously crashing later elsewhere.
The following code causes the issue: https://github.com/zlib-ng/zlib-ng/blob/c255e58dd5e0ec3b2febb29c0905e89032419bcd/deflate.c#L227-228
This should be
The text was updated successfully, but these errors were encountered: