73adb24
From e554695638228b846d49657f31eeff0ca4680e8a Mon Sep 17 00:00:00 2001
73adb24
From: Mark Adler <madler@alumni.caltech.edu>
73adb24
Date: Thu, 15 Dec 2022 09:07:13 -0800
73adb24
Subject: [PATCH] Fix bug in deflateBound() for level 0 and memLevel 9.
73adb24
73adb24
memLevel 9 would cause deflateBound() to assume the use of fixed
73adb24
blocks, even if the compression level was 0, which forces stored
73adb24
blocks. That could result in a bound less than the size of the
73adb24
compressed data. Now level 0 always uses the stored blocks bound.
73adb24
---
73adb24
 deflate.c | 3 ++-
73adb24
 1 file changed, 2 insertions(+), 1 deletion(-)
73adb24
73adb24
diff --git a/deflate.c b/deflate.c
73adb24
index cd538b8..4a512e1 100644
73adb24
--- a/deflate.c
73adb24
+++ b/deflate.c
73adb24
@@ -752,7 +752,8 @@ uLong ZEXPORT deflateBound(strm, sourceLen)
73adb24
 
73adb24
     /* if not default parameters, return one of the conservative bounds */
73adb24
     if (s->w_bits != 15 || s->hash_bits != 8 + 7)
73adb24
-        return (s->w_bits <= s->hash_bits ? fixedlen : storelen) + wraplen;
73adb24
+        return (s->w_bits <= s->hash_bits && s->level ? fixedlen : storelen) +
73adb24
+               wraplen;
73adb24
 
73adb24
     /* default settings: return tight bound for that case -- ~0.03% overhead
73adb24
        plus a small constant */
73adb24
-- 
73adb24
2.38.1
73adb24