richgel999 / lzham_codec

Lossless data compression codec with LZMA-like ratios but 1.5x-8x faster decompression speed, C/C++
Other
693 stars 71 forks source link

lzham_lib_z_deflateInit2 writes zlib header/footer even if negative window_bits passed #13

Open AndrewSav opened 9 years ago

AndrewSav commented 9 years ago

In lzham_lib_z_deflateInit2 function of lzham_lzcomp.cpp there is following code:

 if (method == LZHAM_Z_DEFLATED)
      {
         // Force Deflate to LZHAM with default window_bits.
         method = LZHAM_Z_LZHAM;
         window_bits = LZHAM_Z_DEFAULT_WINDOW_BITS;
      }

A little bit down below we see this:

 if (window_bits > 0)
         comp_params.m_compress_flags |= LZHAM_COMP_FLAG_WRITE_ZLIB_STREAM;

This means that if you pass deflate as methods and -15 as window_bits as you would with zlib and expect it not to write zlib header/adler-32 footer you will be disappointed. The first piece of code will change -15 to 15, and then the second piece of code happily will add the header/footer flag.

Is this intentional?