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=1796283116; b=RbxkDyOHeQnDZlzy+CXc3YKbrM3R7njpHkKU/J2s21euxdWTu+nUI4o7JUpu1xm+0FNh Iyy2vxxCtncDBnSN68xQlFZSJsnSf0h2zD3ObhH6y5N3+WG3UOvoPYt33zjBbjw/0ZomD KMtM2Nkr2FOPYKVziQeY8u5z1a8bfp31NafhpiTlydMaCZ30J/5ij82DW6iToZH7WuvKJ YnCs9vSNs4n7ucWZqeih9Djzq6urpllHkKwsccTD251L1LEk+At7Mp51Zb/h20wX2bVZ9 ofYATlLxVBqYlj5Skj9Q0Lh3Bl2FVq+XLnZhJyRXh3ywT0BiQrg9VAhCMZ1hWf1Zdwg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796283116; 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=L0p/a8cyGnKMZtWObIZwZF5Hj+7kumHqBrR9PRcUFcg=; b=hWoG44oGmBvGbKAtCdAoKe+91BjIo7yGYeBM7af30+11aV104cGZmTxMnGNAd+ULi9Nd Ihvcg2rJE0nSmAjDI3762jMxpFjeJ5FPfRhlrA2DMv2bE4dWogTyHLtkw2WKt0Iy+xGCP ydCz/lBAQ2vj/7od4Wy6UclmxHuwCwQhbqxsUkYULb02DT5f6AEVzAFDn/6P+nuSWsXGp 49mNxm4Vi5ijhztsey1ynOpwoy7gv19Mz1uwE/CEavfDbUic+adjn996N4tJUPu1Bj1xB 4zcSURHtoRU3RlqF0SrGVDx2V5nkotoPlfs4NI+pmALth2uQ40GC7MTiIMjTWbHw3Ow== 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=JN+TyoOe; 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 21741606A332 for ; Thu, 3 Dec 2026 07:31:55 +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=JN+TyoOe Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3FFF1F000C1; Thu, 3 Dec 2026 07:31:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796283115; bh=L0p/a8cyGnKMZtWObIZwZF5Hj+7kumHqBrR9PRcUFcg=; h=From:Date:Subject:References:In-Reply-To:To; b=JN+TyoOe+GrC+4D5KarM9/JeYjM6cdUuBnNwlgkjbwQbC2GeY+evDa7rLNl4W+whT ojQyHthY63TL5JzAP4U2usu5+plewbEIDZestR3N37uL2D16Em/4EllLWmY08Wg9x5 dUZH3LdZCGCt7JoJhCMTlXNfCxPOP05yazGdhrK0= From: Greg Kroah-Hartman Date: Thu, 03 Dec 2026 08:29:56 +0100 Subject: [PATCH 16/21] lib/zlib: update deflate to zlib 1.2.2.1 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-16-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=5000; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=BDwrEJqOclA9c09EgCIK5tlrU2od9LhBhNAPeki7epA=; b=owGbwMvMwCRo6H6F97bub03G02pJDNmCUtlh2utKV734mcjUMm/j3h3R3iXmTSseaV4o3/RYZ Nfpj5xBHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjCRmgUM84v2d7WE1BrWiyw8 NZHJau6amVsrHzHMz2Wo1T/pn2W8u/vRukvaK+c13n4VAgA= X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Sync the kernel deflate code with the zlib 1.2.2.1 release. This involves: - replace the old ascii-vs-binary frequency heuristic in set_data_type() with upstream's printable-character test, and introduce Z_TEXT in zlib.h with Z_ASCII kept as a compatibility alias. - only classify the data when the flushed block actually contains data (stored_len > 0) There were some changes that were not relevant to the kernel copy: - deflateSetHeader() and the gzip header writing state machine (EXTRA/NAME/COMMENT/HCRC states, gzhead/gzindex). The kernel copy is a NO_GZIP build and does not define the gz_header type so not a problem. - the defreq.txt DEBUG instrumentation, which is only for stdio (i.e. userspace), and it was removed again in the future 1.2.2.2 release The kernel is now in sync with zlib commit 9811b53dd9e8 ("zlib 1.2.2.1"). Signed-off-by: Greg Kroah-Hartman --- include/linux/zlib.h | 7 ++++--- include/linux/zutil.h | 2 +- lib/zlib_deflate/deftree.c | 32 ++++++++++++++++++-------------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/include/linux/zlib.h b/include/linux/zlib.h index aa566d10364c..9d203a8f419e 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" */ +/* zlib deflate based on ZLIB_VERSION "1.2.2.1" */ /* zlib inflate based on ZLIB_VERSION "1.2.3" */ /* @@ -171,9 +171,10 @@ typedef z_stream *z_streamp; /* compression strategy; see deflateInit2() below for details */ #define Z_BINARY 0 -#define Z_ASCII 1 +#define Z_TEXT 1 +#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ #define Z_UNKNOWN 2 -/* Possible values of the data_type field */ +/* Possible values of the data_type field (though see inflate()) */ #define Z_DEFLATED 8 /* The deflate compression method (the only one supported in this version) */ diff --git a/include/linux/zutil.h b/include/linux/zutil.h index 4032cfc1e82b..3ad9a50e3e89 100644 --- a/include/linux/zutil.h +++ b/include/linux/zutil.h @@ -1,5 +1,5 @@ /* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-2003 Jean-loup Gailly. + * Copyright (C) 1995-2004 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ diff --git a/lib/zlib_deflate/deftree.c b/lib/zlib_deflate/deftree.c index dbe0eda9a824..d4107392d70c 100644 --- a/lib/zlib_deflate/deftree.c +++ b/lib/zlib_deflate/deftree.c @@ -1,6 +1,6 @@ /* +++ trees.c */ /* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-2003 Jean-loup Gailly + * Copyright (C) 1995-2004 Jean-loup Gailly * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -813,8 +813,9 @@ ulg zlib_tr_flush_block( /* Build the Huffman trees unless a stored block is forced */ if (s->level > 0) { - /* Check if the file is ascii or binary */ - if (s->strm->data_type == Z_UNKNOWN) set_data_type(s); + /* Check if the file is binary or text */ + if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN) + set_data_type(s); /* Construct the literal and distance trees */ build_tree(s, (tree_desc *)(&(s->l_desc))); @@ -1012,22 +1013,25 @@ static void compress_block( } /* =========================================================================== - * Set the data type to ASCII or BINARY, using a crude approximation: - * binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise. - * IN assertion: the fields freq of dyn_ltree are set and the total of all - * frequencies does not exceed 64K (to fit in an int on 16 bit machines). + * Set the data type to BINARY or TEXT, using a crude approximation: + * set it to Z_TEXT if all symbols are either printable characters (33 to 255) + * or white spaces (9 to 13, or 32); or set it to Z_BINARY otherwise. + * IN assertion: the fields Freq of dyn_ltree are set. */ static void set_data_type( deflate_state *s ) { - int n = 0; - unsigned ascii_freq = 0; - unsigned bin_freq = 0; - while (n < 7) bin_freq += s->dyn_ltree[n++].Freq; - while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq; - while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq; - s->strm->data_type = bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII; + int n; + + for (n = 0; n < 9; n++) + if (s->dyn_ltree[n].Freq != 0) + break; + if (n == 9) + for (n = 14; n < 32; n++) + if (s->dyn_ltree[n].Freq != 0) + break; + s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY; } /* =========================================================================== -- 2.56.1