From: Mark Adler Date: Fri, 28 Oct 2016 05:50:43 +0000 (-0700) Subject: Fix bug when level 0 used with Z_HUFFMAN or Z_RLE. X-Git-Tag: 1.9.9-b1~677 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=701cfe90aea324cdc93f8d4eb1b82eb0d42d8a6a;p=thirdparty%2Fzlib-ng.git Fix bug when level 0 used with Z_HUFFMAN or Z_RLE. Compression level 0 requests no compression, using only stored blocks. When Z_HUFFMAN or Z_RLE was used with level 0 (granted, an odd choice, but permitted), the resulting blocks were mostly fixed or dynamic. The reason is that deflate_stored() was not being called in that case. The compressed data was valid, but it was not what the application requested. This commit assures that only stored blocks are emitted for compression level 0, regardless of the strategy selected. --- diff --git a/deflate.c b/deflate.c index 56d073e8e..ef286450a 100644 --- a/deflate.c +++ b/deflate.c @@ -936,7 +936,8 @@ int ZEXPORT deflate(z_stream *strm, int flush) { if (strm->avail_in != 0 || s->lookahead != 0 || (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { block_state bstate; - bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : + bstate = s->level == 0 ? deflate_stored(s, flush) : + s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : s->strategy == Z_RLE ? deflate_rle(s, flush) : #ifdef X86_QUICK_STRATEGY (s->level == 1 && !x86_cpu_has_sse42) ? deflate_fast(s, flush) :