-
Notifications
You must be signed in to change notification settings - Fork 364
Description
For a zlib compressed file that needs to be decompressed by an MCU with very limited memory, I want to use a window size of only 4096. I started by defining TDEFL_LESS_MEMORY
, and changing TDEFL_LZ_DICT_SIZE
to 4096, which leaded to corrupted zlib files. After some more investigation, it appeared I could lower TDEFL_LZ_DICT_SIZE
to 16384 and 8192, but anything below would corrupt the output file.
Eventually I managed to fix it, because I found some hardcoded values in the source of tdefl_compress_normal
:
8U * 1024U
in https://github.com/richgel999/miniz/blob/master/miniz_tdef.c#L1185
and
31 * 1024
in https://github.com/richgel999/miniz/blob/master/miniz_tdef.c#L1234
Changing both of the hardcoded values to 4096 solved the problem, and, in combination with the right TDEFL_LZ_DICT_SIZE
, leaded to valid zlib files with window size 4096.
As I'm not exactly know what I'm messing with ;-) , I didn't want to make this in to a PR. Ideally, it probably should use the window_bits parameter in int mz_inflateInit2(mz_streamp pStream, int window_bits)
(which is restricted to 15 and -15 at the moment, and only used to check if the value is negative or positive).