From 94575859cf7f657f0f31aff4c50761fe3f182699 Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Thu, 27 Oct 2016 22:50:43 -0700 Subject: 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. --- deflate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/deflate.c b/deflate.c index 537c4a3..85e30bc 100644 --- a/deflate.c +++ b/deflate.c @@ -914,9 +914,10 @@ int ZEXPORT deflate (strm, flush) (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { block_state bstate; - bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : - (s->strategy == Z_RLE ? deflate_rle(s, flush) : - (*(configuration_table[s->level].func))(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) : + (*(configuration_table[s->level].func))(s, flush); if (bstate == finish_started || bstate == finish_done) { s->status = FINISH_STATE; -- cgit v1.2.3-55-g6feb