diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2022-12-15 09:07:13 -0800 |
---|---|---|
committer | Hans Kristian Rosbach <hk-github@circlestorm.org> | 2023-03-17 21:27:56 +0100 |
commit | 9d3c3549e338fdbeab0135df389478d5bbf3acc3 (patch) | |
tree | 5ae6bbb6bee64e17f9d3416d60f4757d18847ef1 | |
parent | 99674e057bbf274138d0aef21b79618ede2e99b3 (diff) |
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.
-rw-r--r-- | deflate.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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 */ |