From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796283028; b=X08crRQEKFfj57moKgfWd7gG9e+b3UD6DWkxydyeARg9lsjls1W73rOGrAEjqbv6/qBl vTE8OXm3kOjasV/GhJMvyZeFlZIvDgrK05brYnXawVqRc+IVaZz4jVExs5I4HvPUENIsf 4Cn4wGWgy2bdN6RZFq0fEE3ZpEx/SLKeJGwasaulnG5Qdq7F+aWfrPiF+7/93KFAfI3+D 5hMpskFMr4HD0kBhmWTozz+ci5DLPLj3NUgZJbDqp00oQ6Yk/PmE8vzoFIsE2DQhvFuoz D1Fmdt5G0aPvuaEaZijhGf5cVodlX4Z2U10Ur1baqrEIv1PxEmSH3dRSGO6+ExGJNoQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796283028; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=2xsl/ke1UBB9/u9Iu0LZIngp3gBCzMpYcQUeGyeSHAU=; b=1nbCbkaAak97e4VXPbXwcRsuLh1b3Rf1SgQUKbmMgUfPZ69j2f5MJswlSFQ4IDucj3a3 OgB6ueK3pV4RzgvVFTuc/ncrwXKLdmAIzJbHIoBYR4retZOoXt7YQjnLl2n/XmZaGkQju f7PWxqlg77ndXjj3CeqCVOqjJ/tUtJGmgsMOvlekRmL7RIH9IBRG+zK+omRU/zVHat6qo med7XbnJBaaxeysms3I42qwzlSwR7YkCXVCjY03LGWrsXCIPl58gX5Nr35wjnEyWbiH0d T3jQ9bGlP32TDM659pnfBLNSM8mdeKtjbHpdWM7d68ZXQCrdDmKXBeX0/4l47VnXTCw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=fzuQNKuO; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E32C606A322 for ; Thu, 3 Dec 2026 07:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=fzuQNKuO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 735CE1F00893; Thu, 3 Dec 2026 07:30:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796283028; bh=2xsl/ke1UBB9/u9Iu0LZIngp3gBCzMpYcQUeGyeSHAU=; h=From:Date:Subject:References:In-Reply-To:To; b=fzuQNKuOvQpVl8sn7M7R563mP3e6WouUuP3uOy0JFltv2ozcDp74WV62mXnt7DyH1 wME5kwhfW4vHbnCbeSQrrEyLud5F2Zqton0nV8UcKdBHtR6GyQ+eU6b2Vk31ezLrnZ bjTooIqJhFTKWtawe3pGDeTBcP+mEHB95Ye22wVg= From: Greg Kroah-Hartman Date: Thu, 03 Dec 2026 08:29:45 +0100 Subject: [PATCH 05/21] lib/zlib: update deflate to zlib 1.2.0.2 release X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261203-zlib-sync-v1-5-0d4ec56f1afb@linuxfoundation.org> References: <20261203-zlib-sync-v1-0-0d4ec56f1afb@linuxfoundation.org> In-Reply-To: <20261203-zlib-sync-v1-0-0d4ec56f1afb@linuxfoundation.org> To: linux-kernel@vger.kernel.org, Greg Kroah-Hartman X-Mailer: b4 0.17-dev-73bef X-Developer-Signature: v=1; a=openpgp-sha256; l=8154; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=JBw4OUjMAKPBOCggfnjNxy0tnfoOzhRy/KsRAdEiI98=; b=owGbwMvMwCRo6H6F97bub03G02pJDNmCUlnOV10D1p9l3X2stWvvjnq94LOLGu5vW6n2xplhb f6bdQeWdcSyMAgyMciKKbJ82cZzdH/FIUUvQ9vTMHNYmUCGMHBxCsBEdJIZFszotL6l+PANC4vg vpT0DfeOd1r2VTPMj3Rpy80qjAjeb2j9ueT+8X2Pe796AwA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Sync the kernel deflate code with the zlib 1.2.0.2 release. This involves: - accept windowBits == 8 in zlib_deflateInit2() again, silently forcing it to 9 until the 256-byte-window bug is fixed (matching upstream). The kernel's zlib_deflate_workspacesize() applies the same change so a caller passing 8 sizes the workspace for the 9 that init will actually use. - compute the zlib header compression-level flags from the strategy and level directly: Z_HUFFMAN_ONLY/Z_RLE and levels < 2 now mark the stream as "fastest", matching what the data actually contains. - restructure the 64K-limit handling in fill_window() under a sizeof(int) <= 2 test so the window-slide check is no longer chained behind the 16-bit-only cases. - compile out the TOO_FAR heuristic in deflate_slow() when TOO_FAR is configured >= the window size, but this results in no real change with the default value of 4096. - add missing (uInt) casts in longest_match_fast()'s return. - rename the header guards _ZLIB_H/_Z_UTIL_H to ZLIB_H/ZUTIL_H and fix an RFC URL in a comment. There were some 1.2.0.2 changes that were not relevant to the kernel copy: - ZLIB_VERNUM/zlibCompileFlags - _WIN32_WCE fdopen and vsnprintf detection - the NO_DUMMY_DECL guard for the dummy struct in deflate.c - inflateInit2() documentation updates were already present from the kernel's 1.2.3-based inflate code. The kernel is now in sync with zlib commit 8e34b3a8024c ("zlib 1.2.0.2"). Signed-off-by: Greg Kroah-Hartman --- include/linux/zlib.h | 10 +++++----- include/linux/zutil.h | 6 +++--- lib/zlib_deflate/deflate.c | 47 ++++++++++++++++++++++++++++++---------------- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/include/linux/zlib.h b/include/linux/zlib.h index fe5f7a68fc1a..64a0ceafbb2c 100644 --- a/include/linux/zlib.h +++ b/include/linux/zlib.h @@ -27,12 +27,12 @@ (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). */ -#ifndef _ZLIB_H -#define _ZLIB_H +#ifndef ZLIB_H +#define ZLIB_H #include -/* zlib deflate based on ZLIB_VERSION "1.2.0.1" */ +/* zlib deflate based on ZLIB_VERSION "1.2.0.2" */ /* zlib inflate based on ZLIB_VERSION "1.2.3" */ /* @@ -591,7 +591,7 @@ extern int zlib_deflateInit2(z_streamp strm, int level, int method, int strategy); extern int zlib_inflateInit2(z_streamp strm, int windowBits); -#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL) +#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) struct internal_state {int dummy;}; /* hack for buggy compilers */ #endif @@ -599,4 +599,4 @@ extern int zlib_inflateInit2(z_streamp strm, int windowBits); * return len or negative error code. */ extern int zlib_inflate_blob(void *dst, unsigned dst_sz, const void *src, unsigned src_sz); -#endif /* _ZLIB_H */ +#endif /* ZLIB_H */ diff --git a/include/linux/zutil.h b/include/linux/zutil.h index c77a8d43d12f..2197ac6cff70 100644 --- a/include/linux/zutil.h +++ b/include/linux/zutil.h @@ -10,8 +10,8 @@ /* @(#) $Id: zutil.h,v 1.1 2000/01/01 03:32:23 davem Exp $ */ -#ifndef _Z_UTIL_H -#define _Z_UTIL_H +#ifndef ZUTIL_H +#define ZUTIL_H #include #include @@ -97,4 +97,4 @@ static inline uLong zlib_adler32(uLong adler, return (s2 << 16) | s1; } -#endif /* _Z_UTIL_H */ +#endif /* ZUTIL_H */ diff --git a/lib/zlib_deflate/deflate.c b/lib/zlib_deflate/deflate.c index a703adf97820..66b4bfd260a8 100644 --- a/lib/zlib_deflate/deflate.c +++ b/lib/zlib_deflate/deflate.c @@ -38,7 +38,7 @@ * REFERENCES * * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". - * Available in ftp://ds.internic.net/rfc/rfc1951.txt + * Available in http://www.ietf.org/rfc/rfc1951.txt * * A description of the Rabin and Karp algorithm is given in the book * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. @@ -215,10 +215,11 @@ int zlib_deflateInit2( windowBits = -windowBits; } if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || - windowBits < 9 || windowBits > 15 || level < 0 || level > 9 || + windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || strategy < 0 || strategy > Z_RLE) { return Z_STREAM_ERROR; } + if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ /* * Direct the workspace's pointers to the chunks that were allocated @@ -352,9 +353,16 @@ int zlib_deflate( if (s->status == INIT_STATE) { uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; - uInt level_flags = (s->level-1) >> 1; + uInt level_flags; - if (level_flags > 3) level_flags = 3; + if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) + level_flags = 0; + else if (s->level < 6) + level_flags = 1; + else if (s->level == 6) + level_flags = 2; + else + level_flags = 3; header |= (level_flags << 6); if (s->strstart != 0) header |= PRESET_DICT; header += 31 - (header % 31); @@ -753,7 +761,7 @@ static uInt longest_match_fast( if (len < MIN_MATCH) return MIN_MATCH - 1; s->match_start = cur_match; - return len <= s->lookahead ? len : s->lookahead; + return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; } #ifdef DEBUG_ZLIB @@ -808,19 +816,22 @@ static void fill_window( more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); /* Deal with !@#$% 64K limit: */ - if (more == 0 && s->strstart == 0 && s->lookahead == 0) { - more = wsize; + if (sizeof(int) <= 2) { + if (more == 0 && s->strstart == 0 && s->lookahead == 0) { + more = wsize; - } else if (more == (unsigned)(-1)) { - /* Very unlikely, but possible on 16 bit machine if strstart == 0 - * and lookahead == 1 (input done one byte at time) - */ - more--; + } else if (more == (unsigned)(-1)) { + /* Very unlikely, but possible on 16 bit machine if + * strstart == 0 && lookahead == 1 (input done one byte at time) + */ + more--; + } + } /* If the window is almost full and there is insufficient lookahead, * move the upper half to the lower one to make room in the upper half. */ - } else if (s->strstart >= wsize+MAX_DIST(s)) { + if (s->strstart >= wsize+MAX_DIST(s)) { memcpy((char *)s->window, (char *)s->window+wsize, (unsigned)wsize); @@ -1118,9 +1129,12 @@ static block_state deflate_slow( } /* longest_match() or longest_match_fast() sets match_start */ - if (s->match_length <= 5 && (s->strategy == Z_FILTERED || - (s->match_length == MIN_MATCH && - s->strstart - s->match_start > TOO_FAR))) { + if (s->match_length <= 5 && (s->strategy == Z_FILTERED +#if TOO_FAR < 32768 + || (s->match_length == MIN_MATCH && + s->strstart - s->match_start > TOO_FAR) +#endif + )) { /* If prev_match is also MIN_MATCH, match_start is garbage * but we will ignore the current match anyway. @@ -1193,6 +1207,7 @@ int zlib_deflate_workspacesize(int windowBits, int memLevel) { if (windowBits < 0) /* undocumented feature: suppress zlib header */ windowBits = -windowBits; + if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ /* Since the return value is typically passed to vmalloc() unchecked... */ BUG_ON(memLevel < 1 || memLevel > MAX_MEM_LEVEL || windowBits < 9 || -- 2.56.1