summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2022-12-15 09:07:13 -0800
committerHans Kristian Rosbach <hk-github@circlestorm.org>2023-03-17 21:27:56 +0100
commit9d3c3549e338fdbeab0135df389478d5bbf3acc3 (patch)
tree5ae6bbb6bee64e17f9d3416d60f4757d18847ef1
parent99674e057bbf274138d0aef21b79618ede2e99b3 (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.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/deflate.c b/deflate.c
index 92c2b44..d01ca44 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 */