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=1796283125; b=DLBkKs39QMyM2p35UQ+QcH9Y9VeSXxFrt76ApewCz31FWnKpUtj/bnrgoePVJWY8SkDC MPACMZYqec/7kSPu3JEr1u/d5bPVjtAvpnQVEA8qWtfZE0qvB10hwpTKUck8BCpNb8njq tzWDBKSSaRY3j1kIq3zzsPMWeLLb+GHxiGSkLBxCkymNHzJGFmx0MoVT97vuyELnUgs8/ KCwGYAcetaKIvduC0r9pGc3TJfXM+FNpYSd+Bbvq1QceaCJRfL/nRBO/5s8GDjxvaKO0P c5DwEtImd7dYeEjbarKsDhOzcTAmt4mtomZE5p55imQH6CjEl1wEaPGmI9wtMNSDzYQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796283125; 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=sggElLf5iDVUtCwTEAS8DCBXrqsb/Qdw+nP/S1HPo4o=; b=Pd7kIPL+2L+i7e2+IMzBF8/QDXJivNI6HhlJuNBGYSGPZP/BE9CkjEGw9mZZVPo/HhWp ol3N37iYctGBKR/DXzLKAB88VA0w7lg/n0q41fNWYl8eeyl7YFjtlyYfwc6b+sSWxmAaq UhlsBUohQ0XvFvSLX7DWeXgjOYUL13W72MiuaH5GJAKFcf2f7+257esCWrl8dUzvV+lLD rkiMjrEN+PgE+G9lm4iITJKjLiYNyK84t8723IVdYWFZf1z7MysHejElhzeajojkKNGPV xI1UlqNS5AchgMSL49gDIskJh5XJ7lTYQEB7m2vKE+MVSEg1K0jC+MDqmZiZnxuGbaA== 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=O366cgT+; 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 497D0606A32C for ; Thu, 3 Dec 2026 07:32:05 +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=O366cgT+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20D441F008A0; Thu, 3 Dec 2026 07:32:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796283124; bh=sggElLf5iDVUtCwTEAS8DCBXrqsb/Qdw+nP/S1HPo4o=; h=From:Date:Subject:References:In-Reply-To:To; b=O366cgT+4pmyYU0vLQpff5Etr1lYTmkbgXu8h/cd6MTl62ymnO0ETxhVr/0r6YcEi 8lZwmovvUBAt+820qbC38JZVkAC52kKypvHNNGiipV3GhO0AFm0s1zlef04HgjxVXE WsJEqRcuTIOstbNLSVwLVbHlhPwvKAn6RBwDXEw0= From: Greg Kroah-Hartman Date: Thu, 03 Dec 2026 08:29:58 +0100 Subject: [PATCH 18/21] lib/zlib: update deflate to zlib 1.2.2.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-18-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=5341; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=2/56w02BMTtls00k3OZzYheUd50l00S/sK+arzYkAUY=; b=owGbwMvMwCRo6H6F97bub03G02pJDNmCUtkikWvS9lwqsWFKyL3mfP1M2Os3vwrEE7OfpFgUu 4cVZHN1xLIwCDIxyIopsnzZxnN0f8UhRS9D29Mwc1iZQIYwcHEKwET6DjHMd8r6OnHK9L7W6lne N0W3bApLeKPUyDA/rTtJ2eF8znxb9/ncwaqM/ywm2rsDAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Sync the kernel deflate code with the zlib 1.2.2.2 release. This involves: - add the Z_FIXED strategy, which prevents the use of dynamic Huffman codes so decoding can start earlier with a simpler decoder: _tr_flush_block() picks the static trees unconditionally for it, and the match finders treat it like the default strategy - rewrite the strategy dispatch in deflate_fast()/deflate_slow() as explicit != Z_HUFFMAN_ONLY && != Z_RLE tests so Z_FIXED (numerically above Z_RLE) uses longest_match() - expand the longest_match() comment to document the intentional reads of uninitialized window bytes beyond the lookahead - emit OS_CODE instead of 255 in the (compiled-out) gzip header path There was one change that was not relevant to the kernel copy: - deflateCopy()'s zmemcpy conversion is not needed The kernel is now in sync with zlib commit 0484693e1723 ("zlib 1.2.2.2"). Signed-off-by: Greg Kroah-Hartman --- include/linux/zlib.h | 3 ++- lib/zlib_deflate/deflate.c | 15 ++++++++++----- lib/zlib_deflate/deftree.c | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/linux/zlib.h b/include/linux/zlib.h index 9d203a8f419e..95d90b51970c 100644 --- a/include/linux/zlib.h +++ b/include/linux/zlib.h @@ -32,7 +32,7 @@ #include -/* zlib deflate based on ZLIB_VERSION "1.2.2.1" */ +/* zlib deflate based on ZLIB_VERSION "1.2.2.2" */ /* zlib inflate based on ZLIB_VERSION "1.2.3" */ /* @@ -167,6 +167,7 @@ typedef z_stream *z_streamp; #define Z_FILTERED 1 #define Z_HUFFMAN_ONLY 2 #define Z_RLE 3 +#define Z_FIXED 4 #define Z_DEFAULT_STRATEGY 0 /* compression strategy; see deflateInit2() below for details */ diff --git a/lib/zlib_deflate/deflate.c b/lib/zlib_deflate/deflate.c index d6d29f63b572..f7ff13a15434 100644 --- a/lib/zlib_deflate/deflate.c +++ b/lib/zlib_deflate/deflate.c @@ -222,7 +222,7 @@ int zlib_deflateInit2( #endif if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || - strategy < 0 || strategy > Z_RLE) { + strategy < 0 || strategy > Z_FIXED) { return Z_STREAM_ERROR; } if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ @@ -374,7 +374,7 @@ int zlib_deflate( put_byte(s, s->level == 9 ? 2 : (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? 4 : 0)); - put_byte(s, 255); + put_byte(s, OS_CODE); s->status = BUSY_STATE; strm->adler = crc32(0L, NULL, 0); } @@ -664,7 +664,12 @@ static uInt longest_match( match = s->window + cur_match; /* Skip to next match if the match length cannot increase - * or if the match length is less than 2: + * or if the match length is less than 2. Note that the checks below + * for insufficient lookahead only occur occasionally for performance + * reasons. Therefore uninitialized memory will be accessed, and + * conditional jumps will be made that depend on those values. + * However the length of the match is limited to the lookahead, so + * the output of deflate is not affected by the uninitialized values. */ #if (defined(UNALIGNED_OK) && MAX_MATCH == 258) /* This code assumes sizeof(unsigned short) == 2. Do not use @@ -1065,7 +1070,7 @@ static block_state deflate_fast( * of window index 0 (in particular we have to avoid a match * of the string with itself at the start of the input file). */ - if (s->strategy < Z_HUFFMAN_ONLY) { + if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) { s->match_length = longest_match (s, hash_head); } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) { s->match_length = longest_match_fast (s, hash_head); @@ -1165,7 +1170,7 @@ static block_state deflate_slow( * of window index 0 (in particular we have to avoid a match * of the string with itself at the start of the input file). */ - if (s->strategy < Z_HUFFMAN_ONLY) { + if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) { s->match_length = longest_match (s, hash_head); } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) { s->match_length = longest_match_fast (s, hash_head); diff --git a/lib/zlib_deflate/deftree.c b/lib/zlib_deflate/deftree.c index baa8d37fd094..b98feac2d498 100644 --- a/lib/zlib_deflate/deftree.c +++ b/lib/zlib_deflate/deftree.c @@ -872,7 +872,7 @@ void zlib_tr_flush_block( #ifdef FORCE_STATIC } else if (static_lenb >= 0) { /* force static trees */ #else - } else if (static_lenb == opt_lenb) { + } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { #endif send_bits(s, (STATIC_TREES<<1)+eof, 3); compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); -- 2.56.1