From: Mark Adler Date: Thu, 15 Dec 2022 17:07:13 +0000 (-0800) Subject: Fix bug in deflateBound() for level 0 and memLevel 9. X-Git-Tag: 2.0.7~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9d3c3549e338fdbeab0135df389478d5bbf3acc3;p=thirdparty%2Fzlib-ng.git Fix bug in deflateBound() for level 0 and memLevel 9. memLevel 9 would cause deflateBound() to assume the use of fixed blocks, even if the compression level was 0, which forces stored blocks. That could result in a bound less than the size of the compressed data. Now level 0 always uses the stored blocks bound. --- diff --git a/deflate.c b/deflate.c index 92c2b44f..d01ca44a 100644 --- a/deflate.c +++ b/deflate.c @@ -715,8 +715,15 @@ unsigned long Z_EXPORT PREFIX(deflateBound)(PREFIX3(stream) *strm, unsigned long /* if not default parameters, return conservative bound */ if (DEFLATE_NEED_CONSERVATIVE_BOUND(strm) || /* hook for IBM Z DFLTCC */ - s->w_bits != 15 || HASH_BITS < 15) + s->w_bits != 15 || HASH_BITS < 15) { + if (s->level == 0) { + /* upper bound for stored blocks with length 127 (memLevel == 1) -- + ~4% overhead plus a small constant */ + complen = sourceLen + (sourceLen >> 5) + (sourceLen >> 7) + (sourceLen >> 11) + 7; + } + return complen + wraplen; + } #ifndef NO_QUICK_STRATEGY return sourceLen /* The source size itself */