]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Make deflateBound() more conservative and handle negative wrap.
authorMark Adler <madler@alumni.caltech.edu>
Sat, 4 Apr 2026 01:16:25 +0000 (18:16 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Wed, 29 Jul 2026 09:42:30 +0000 (11:42 +0200)
Use GZIP_WRAPLEN instead of 6 when parameters are unavailable, and
handle negative s->wrap values in the switch.

Upstream: https://github.com/madler/zlib/commit/a8c321be

deflate.c

index 043c35fbf6ed2dd8837a57f6f7c2f2cc21257d2a..3471238069d525fd618e3efe4bc76609ef39f97b 100644 (file)
--- a/deflate.c
+++ b/deflate.c
@@ -698,13 +698,13 @@ unsigned long Z_EXPORT PREFIX(deflateBound)(PREFIX3(stream) *strm, unsigned long
     complen = sourceLen + ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
     DEFLATE_BOUND_ADJUST_COMPLEN(strm, complen, sourceLen);  /* hook for IBM Z DFLTCC */
 
-    /* if can't get parameters, return conservative bound plus zlib wrapper */
+    /* if can't get parameters, return conservative bound plus a wrapper */
     if (deflateStateCheck(strm))
-        return complen + 6;
+        return complen + GZIP_WRAPLEN;
 
     /* compute wrapper length */
     s = strm->state;
-    switch (s->wrap) {
+    switch (ABS(s->wrap)) {
     case 0:                                 /* raw deflate */
         wraplen = 0;
         break;