From b5be18e4bfb5f88c3e6485e95e8fbae56e146f97 Mon Sep 17 00:00:00 2001 From: Force Charlie <6904176+fcharlie@users.noreply.github.com> Date: Fri, 1 Mar 2024 13:11:20 +0800 Subject: [PATCH] [zlib] Fix deflateBound() with chromium_zlib_hash and non-default memLevel --- lib/archive/zlib/deflate.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/archive/zlib/deflate.c b/lib/archive/zlib/deflate.c index 4920e700..43711588 100644 --- a/lib/archive/zlib/deflate.c +++ b/lib/archive/zlib/deflate.c @@ -923,6 +923,12 @@ uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen) { wraplen = 6; } + /* With Chromium's hashing, s->hash_bits may not correspond to the + memLevel, making the computations below incorrect. Return the + conservative bound. */ + if (s->chromium_zlib_hash) + return (fixedlen > storelen ? fixedlen : storelen) + wraplen; + /* if not default parameters, return one of the conservative bounds */ if (s->w_bits != 15 || s->hash_bits != 8 + 7) return (s->w_bits <= s->hash_bits && s->level ? fixedlen : storelen) +