* [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream
@ 2026-12-03 7:29 Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 01/21] MAINTAINERS: add myself as the zlib maintainer Greg Kroah-Hartman
` (20 more replies)
0 siblings, 21 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
The in-kernel version of zlib has not been updated for a very very long
time. There have been many fixes and updates to it over the years, so
start to chip away at the differences between the kernel version and
upstream.
This initial series is just some simple version updates and other very
minor changes, along with a MAINTAINERS file update, so that I will be
on the hook for finishing the sync "soon". The overall number of
changes to bring the kernel version in sync is well over 100, so this
will take a while...
I'll probably route this through the char/misc git tree for now as it's
simplest to do it that way on my end. Anyone having any objections to
this, just let me know!
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
Greg Kroah-Hartman (21):
MAINTAINERS: add myself as the zlib maintainer
lib/zlib: update deflate to zlib 1.1.4 release
lib/zlib: update deflate to zlib 1.2.0 release
lib/zlib: update deflate to zlib 1.2.0.1 release
lib/zlib: update deflate to zlib 1.2.0.2 release
lib/zlib: update deflate to zlib 1.2.0.3 release
lib/zlib: update deflate to zlib 1.2.0.4 release
lib/zlib: update deflate to zlib 1.2.0.5 release
lib/zlib: update deflate to zlib 1.2.0.6 release
lib/zlib: update deflate to zlib 1.2.0.7 release
lib/zlib: update deflate to zlib 1.2.0.8 release
lib/zlib: update deflate to zlib 1.2.1 release
lib/zlib: update deflate to zlib 1.2.1.1 release
lib/zlib: update deflate to zlib 1.2.1.2 release
lib/zlib: update deflate to zlib 1.2.2 release
lib/zlib: update deflate to zlib 1.2.2.1 release
lib/zlib: catch code up to the real zlib 1.1.3
lib/zlib: update deflate to zlib 1.2.2.2 release
lib/zlib: update deflate to zlib 1.2.2.3 release
lib/zlib: update deflate to zlib 1.2.2.4 release
lib/zlib: update deflate to zlib 1.2.3 release
MAINTAINERS | 8 +
include/linux/zlib.h | 35 ++--
include/linux/zutil.h | 16 +-
lib/zlib_deflate/deflate.c | 496 +++++++++++++++++++++++++++++++--------------
lib/zlib_deflate/deftree.c | 219 ++++++++++----------
lib/zlib_deflate/defutil.h | 44 ++--
6 files changed, 508 insertions(+), 310 deletions(-)
---
base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
change-id: 20261203-zlib-sync-1bfbc0cfa78c
Best regards,
--
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 01/21] MAINTAINERS: add myself as the zlib maintainer
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 02/21] lib/zlib: update deflate to zlib 1.1.4 release Greg Kroah-Hartman
` (19 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
I'm not "maintaining" the code, but I'll be responsible for syncing the
in-kernel version with the upstream zlib changes as no one seems to have
been paying attention to anything happening there for a very very long
time.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
MAINTAINERS | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 84cb98ef4c49..470696558747 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -30889,6 +30889,14 @@ L: linux-kernel@vger.kernel.org
S: Maintained
F: arch/x86/kernel/cpu/zhaoxin.c
+ZLIB LIBRARY
+M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+S: Supported
+F: include/linux/zlib.h
+F: lib/zlib_deflate/
+F: lib/zlib_dfltcc/
+F: lib/zlib_inflate/
+
ZONED BLOCK DEVICE (BLOCK LAYER)
M: Damien Le Moal <dlemoal@kernel.org>
L: linux-block@vger.kernel.org
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 02/21] lib/zlib: update deflate to zlib 1.1.4 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 01/21] MAINTAINERS: add myself as the zlib maintainer Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 03/21] lib/zlib: update deflate to zlib 1.2.0 release Greg Kroah-Hartman
` (18 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
The only change in the deflate code in zlib 1.1.4 was to reject
windowBits == 8 in deflateInit2(). This change was already done in the
kernel before deflate.c was moved to the current place, so just update
the version numbers and drop some trailing whitespace to bring the code
up to date.
The kernel is now in sync with zlib commit a383133c4e7b ("zlib 1.1.4").
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/zlib.h | 2 +-
lib/zlib_deflate/deflate.c | 4 ++--
lib/zlib_deflate/deftree.c | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index 78ede944c082..abd3320d7c48 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -32,7 +32,7 @@
#include <linux/zconf.h>
-/* zlib deflate based on ZLIB_VERSION "1.1.3" */
+/* zlib deflate based on ZLIB_VERSION "1.1.4" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
/*
diff --git a/lib/zlib_deflate/deflate.c b/lib/zlib_deflate/deflate.c
index 8fb2a3e17c0e..1f5a40e8d437 100644
--- a/lib/zlib_deflate/deflate.c
+++ b/lib/zlib_deflate/deflate.c
@@ -1,7 +1,7 @@
/* +++ deflate.c */
/* deflate.c -- compress data using the deflation algorithm
- * Copyright (C) 1995-1996 Jean-loup Gailly.
- * For conditions of distribution and use, see copyright notice in zlib.h
+ * Copyright (C) 1995-2002 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 a4a34da512fe..eee325ebc351 100644
--- a/lib/zlib_deflate/deftree.c
+++ b/lib/zlib_deflate/deftree.c
@@ -1,7 +1,7 @@
/* +++ trees.c */
/* trees.c -- output deflated data using Huffman coding
- * Copyright (C) 1995-1996 Jean-loup Gailly
- * For conditions of distribution and use, see copyright notice in zlib.h
+ * Copyright (C) 1995-2002 Jean-loup Gailly
+ * For conditions of distribution and use, see copyright notice in zlib.h
*/
/*
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 03/21] lib/zlib: update deflate to zlib 1.2.0 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 01/21] MAINTAINERS: add myself as the zlib maintainer Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 02/21] lib/zlib: update deflate to zlib 1.1.4 release Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 04/21] lib/zlib: update deflate to zlib 1.2.0.1 release Greg Kroah-Hartman
` (17 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
Sync the kernel deflate code with the zlib 1.2.0 release.
This involves:
- open-code the depth comparison in build_tree() instead of using a
MAX() macro (upstream removed the macro; the kernel copy used the
kernel's max() here which was the same, if not better, but oh
well...)
- drop the check_func typedef from zutil.h; nothing has used it since
the inflate code was rewritten (the kernel inflate is already based
on 1.2.3 and does not use it)
- comment and copyright updates
There were some 1.2.0 changes that were not relevant to the kernel copy:
- the deflate_copyright string and version handshake.
- marking the state FINISH_STATE when allocation fails in deflateInit2
(the kernel workspace is preallocated by the caller, there is no
failure path).
- deflateSetDictionary() raw mode support and deflateParams().
- deflateBound(), new in 1.2.0, already exists in the kernel copy as a
much simpler inline function in zlib.h using the same formula.
The kernel is now in sync with zlib commit 7c2a874e50b8 ("zlib 1.2.0").
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/zlib.h | 2 +-
include/linux/zutil.h | 8 +-------
lib/zlib_deflate/deflate.c | 2 +-
lib/zlib_deflate/deftree.c | 7 ++++---
4 files changed, 7 insertions(+), 12 deletions(-)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index abd3320d7c48..2e04200282d5 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -32,7 +32,7 @@
#include <linux/zconf.h>
-/* zlib deflate based on ZLIB_VERSION "1.1.4" */
+/* zlib deflate based on ZLIB_VERSION "1.2.0" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
/*
diff --git a/include/linux/zutil.h b/include/linux/zutil.h
index 663689521759..c77a8d43d12f 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-1998 Jean-loup Gailly.
+ * Copyright (C) 1995-2003 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -42,12 +42,6 @@ typedef unsigned long ulg;
# define OS_CODE 0x03 /* assume Unix */
#endif
- /* functions */
-
-typedef uLong (*check_func) (uLong check, const Byte *buf,
- uInt len);
-
-
/* checksum functions */
#define BASE 65521L /* largest prime smaller than 65536 */
diff --git a/lib/zlib_deflate/deflate.c b/lib/zlib_deflate/deflate.c
index 1f5a40e8d437..2cf1e3500104 100644
--- a/lib/zlib_deflate/deflate.c
+++ b/lib/zlib_deflate/deflate.c
@@ -1,6 +1,6 @@
/* +++ deflate.c */
/* deflate.c -- compress data using the deflation algorithm
- * Copyright (C) 1995-2002 Jean-loup Gailly.
+ * Copyright (C) 1995-2003 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 eee325ebc351..2b98e56a713f 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-2002 Jean-loup Gailly
+ * Copyright (C) 1995-2003 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -540,7 +540,8 @@ static void build_tree(
/* Create a new node father of n and m */
tree[node].Freq = tree[n].Freq + tree[m].Freq;
- s->depth[node] = (uch) (max(s->depth[n], s->depth[m]) + 1);
+ s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
+ s->depth[n] : s->depth[m]) + 1);
tree[n].Dad = tree[m].Dad = (ush)node;
#ifdef DUMP_BL_TREE
if (tree == s->bl_tree) {
@@ -832,7 +833,7 @@ ulg zlib_tr_flush_block(
*/
max_blindex = build_bl_tree(s);
- /* Determine the best encoding. Compute first the block length in bytes*/
+ /* Determine the best encoding. Compute the block lengths in bytes. */
opt_lenb = (s->opt_len+3+7)>>3;
static_lenb = (s->static_len+3+7)>>3;
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 04/21] lib/zlib: update deflate to zlib 1.2.0.1 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (2 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 03/21] lib/zlib: update deflate to zlib 1.2.0 release Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 05/21] lib/zlib: update deflate to zlib 1.2.0.2 release Greg Kroah-Hartman
` (16 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
Sync the kernel deflate code with the zlib 1.2.0.1 release.
This involves:
- add the Z_RLE compression strategy which limits match distances to
one (run-length encoding) makeing it almost as fast as
Z_HUFFMAN_ONLY but with better compression for PNG-style data.
- convert the deflate sources from tabs to spaces and strip trailing
whitespace.
- fix the Z_BUFF_ERROR typo in a comment.
There were some 1.2.0.1 changes that were not relevant to the kernel
copy:
- FASTEST build variant.
- deflateInit_/deflateParams/deflateSetDictionary/deflateCopy and
gen_trees_header changes as these functions are not in the kernel
copy.
- vsnprintf detection in zutil.h.
The kernel is now in sync with zlib commit 13a294f044ef ("zlib 1.2.0.1").
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/zlib.h | 21 ++--
lib/zlib_deflate/deflate.c | 282 +++++++++++++++++++++++++++------------------
lib/zlib_deflate/deftree.c | 138 +++++++++++-----------
lib/zlib_deflate/defutil.h | 30 ++---
4 files changed, 268 insertions(+), 203 deletions(-)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index 2e04200282d5..fe5f7a68fc1a 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -32,7 +32,7 @@
#include <linux/zconf.h>
-/* zlib deflate based on ZLIB_VERSION "1.2.0" */
+/* zlib deflate based on ZLIB_VERSION "1.2.0.1" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
/*
@@ -166,6 +166,7 @@ typedef z_stream *z_streamp;
#define Z_FILTERED 1
#define Z_HUFFMAN_ONLY 2
+#define Z_RLE 3
#define Z_DEFAULT_STRATEGY 0
/* compression strategy; see deflateInit2() below for details */
@@ -485,14 +486,16 @@ extern int deflateInit2 (z_streamp strm,
The strategy parameter is used to tune the compression algorithm. Use the
value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
- filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
- string match). Filtered data consists mostly of small values with a
- somewhat random distribution. In this case, the compression algorithm is
- tuned to compress them better. The effect of Z_FILTERED is to force more
- Huffman coding and less string matching; it is somewhat intermediate
- between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
- the compression ratio but not the correctness of the compressed output even
- if it is not set appropriately.
+ filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
+ string match), or Z_RLE to limit match distances to one (run-length
+ encoding). Filtered data consists mostly of small values with a somewhat
+ random distribution. In this case, the compression algorithm is tuned to
+ compress them better. The effect of Z_FILTERED is to force more Huffman
+ coding and less string matching; it is somewhat intermediate between
+ Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
+ Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
+ parameter only affects the compression ratio but not the correctness of the
+ compressed output even if it is not set appropriately.
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
diff --git a/lib/zlib_deflate/deflate.c b/lib/zlib_deflate/deflate.c
index 2cf1e3500104..a703adf97820 100644
--- a/lib/zlib_deflate/deflate.c
+++ b/lib/zlib_deflate/deflate.c
@@ -77,6 +77,7 @@ static void lm_init (deflate_state *s);
static void putShortMSB (deflate_state *s, uInt b);
static int read_buf (z_streamp strm, Byte *buf, unsigned size);
static uInt longest_match (deflate_state *s, IPos cur_match);
+static uInt longest_match_fast (deflate_state *s, IPos cur_match);
#ifdef DEBUG_ZLIB
static void check_match (deflate_state *s, IPos start, IPos match,
@@ -183,12 +184,12 @@ static const config configuration_table[10] = {
/* ========================================================================= */
int zlib_deflateInit2(
- z_streamp strm,
- int level,
- int method,
- int windowBits,
- int memLevel,
- int strategy
+ z_streamp strm,
+ int level,
+ int method,
+ int windowBits,
+ int memLevel,
+ int strategy
)
{
deflate_state *s;
@@ -215,7 +216,7 @@ int zlib_deflateInit2(
}
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
windowBits < 9 || windowBits > 15 || level < 0 || level > 9 ||
- strategy < 0 || strategy > Z_HUFFMAN_ONLY) {
+ strategy < 0 || strategy > Z_RLE) {
return Z_STREAM_ERROR;
}
@@ -277,11 +278,11 @@ int zlib_deflateInit2(
/* ========================================================================= */
int zlib_deflateReset(
- z_streamp strm
+ z_streamp strm
)
{
deflate_state *s;
-
+
if (strm == NULL || strm->state == NULL)
return Z_STREAM_ERROR;
@@ -314,31 +315,31 @@ int zlib_deflateReset(
* pending_buf.
*/
static void putShortMSB(
- deflate_state *s,
- uInt b
+ deflate_state *s,
+ uInt b
)
{
put_byte(s, (Byte)(b >> 8));
put_byte(s, (Byte)(b & 0xff));
-}
+}
/* ========================================================================= */
int zlib_deflate(
- z_streamp strm,
- int flush
+ z_streamp strm,
+ int flush
)
{
int old_flush; /* value of flush param for previous deflate call */
deflate_state *s;
if (strm == NULL || strm->state == NULL ||
- flush > Z_FINISH || flush < 0) {
+ flush > Z_FINISH || flush < 0) {
return Z_STREAM_ERROR;
}
s = (deflate_state *) strm->state;
if ((strm->next_in == NULL && strm->avail_in != 0) ||
- (s->status == FINISH_STATE && flush != Z_FINISH)) {
+ (s->status == FINISH_STATE && flush != Z_FINISH)) {
return Z_STREAM_ERROR;
}
if (strm->avail_out == 0) return Z_BUF_ERROR;
@@ -355,40 +356,40 @@ int zlib_deflate(
if (level_flags > 3) level_flags = 3;
header |= (level_flags << 6);
- if (s->strstart != 0) header |= PRESET_DICT;
+ if (s->strstart != 0) header |= PRESET_DICT;
header += 31 - (header % 31);
s->status = BUSY_STATE;
putShortMSB(s, header);
- /* Save the adler32 of the preset dictionary: */
- if (s->strstart != 0) {
- putShortMSB(s, (uInt)(strm->adler >> 16));
- putShortMSB(s, (uInt)(strm->adler & 0xffff));
- }
- strm->adler = 1L;
+ /* Save the adler32 of the preset dictionary: */
+ if (s->strstart != 0) {
+ putShortMSB(s, (uInt)(strm->adler >> 16));
+ putShortMSB(s, (uInt)(strm->adler & 0xffff));
+ }
+ strm->adler = 1L;
}
/* Flush as much pending output as possible */
if (s->pending != 0) {
flush_pending(strm);
if (strm->avail_out == 0) {
- /* Since avail_out is 0, deflate will be called again with
- * more output space, but possibly with both pending and
- * avail_in equal to zero. There won't be anything to do,
- * but this is not an error situation so make sure we
- * return OK instead of BUF_ERROR at next call of deflate:
+ /* Since avail_out is 0, deflate will be called again with
+ * more output space, but possibly with both pending and
+ * avail_in equal to zero. There won't be anything to do,
+ * but this is not an error situation so make sure we
+ * return OK instead of BUF_ERROR at next call of deflate:
*/
- s->last_flush = -1;
- return Z_OK;
- }
+ s->last_flush = -1;
+ return Z_OK;
+ }
/* Make sure there is something to do and avoid duplicate consecutive
* flushes. For repeated and useless calls with Z_FINISH, we keep
- * returning Z_STREAM_END instead of Z_BUFF_ERROR.
+ * returning Z_STREAM_END instead of Z_BUF_ERROR.
*/
} else if (strm->avail_in == 0 && flush <= old_flush &&
- flush != Z_FINISH) {
+ flush != Z_FINISH) {
return Z_BUF_ERROR;
}
@@ -403,32 +404,32 @@ int zlib_deflate(
(flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
block_state bstate;
- bstate = DEFLATE_HOOK(strm, flush, &bstate) ? bstate :
- (*(configuration_table[s->level].func))(s, flush);
+ bstate = DEFLATE_HOOK(strm, flush, &bstate) ? bstate :
+ (*(configuration_table[s->level].func))(s, flush);
if (bstate == finish_started || bstate == finish_done) {
s->status = FINISH_STATE;
}
if (bstate == need_more || bstate == finish_started) {
- if (strm->avail_out == 0) {
- s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
- }
- return Z_OK;
- /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
- * of deflate should use the same flush parameter to make sure
- * that the flush is complete. So we don't have to output an
- * empty block here, this will be done at next call. This also
- * ensures that for a very small output buffer, we emit at most
- * one empty block.
- */
- }
+ if (strm->avail_out == 0) {
+ s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
+ }
+ return Z_OK;
+ /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
+ * of deflate should use the same flush parameter to make sure
+ * that the flush is complete. So we don't have to output an
+ * empty block here, this will be done at next call. This also
+ * ensures that for a very small output buffer, we emit at most
+ * one empty block.
+ */
+ }
if (bstate == block_done) {
if (flush == Z_PARTIAL_FLUSH) {
zlib_tr_align(s);
- } else if (flush == Z_PACKET_FLUSH) {
- /* Output just the 3-bit `stored' block type value,
- but not a zero length. */
- zlib_tr_stored_type_only(s);
+ } else if (flush == Z_PACKET_FLUSH) {
+ /* Output just the 3-bit `stored' block type value,
+ but not a zero length. */
+ zlib_tr_stored_type_only(s);
} else { /* FULL_FLUSH or SYNC_FLUSH */
zlib_tr_stored_block(s, (char*)0, 0L, 0);
/* For a full flush, this empty block will be recognized
@@ -439,10 +440,10 @@ int zlib_deflate(
}
}
flush_pending(strm);
- if (strm->avail_out == 0) {
- s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
- return Z_OK;
- }
+ if (strm->avail_out == 0) {
+ s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
+ return Z_OK;
+ }
}
}
Assert(strm->avail_out > 0, "bug2");
@@ -450,27 +451,27 @@ int zlib_deflate(
if (flush != Z_FINISH) return Z_OK;
if (!s->noheader) {
- /* Write zlib trailer (adler32) */
- putShortMSB(s, (uInt)(strm->adler >> 16));
- putShortMSB(s, (uInt)(strm->adler & 0xffff));
+ /* Write zlib trailer (adler32) */
+ putShortMSB(s, (uInt)(strm->adler >> 16));
+ putShortMSB(s, (uInt)(strm->adler & 0xffff));
}
flush_pending(strm);
/* If avail_out is zero, the application will call deflate again
* to flush the rest.
*/
if (!s->noheader) {
- s->noheader = -1; /* write the trailer only once! */
+ s->noheader = -1; /* write the trailer only once! */
}
if (s->pending == 0) {
- Assert(s->bi_valid == 0, "bi_buf not flushed");
- return Z_STREAM_END;
+ Assert(s->bi_valid == 0, "bi_buf not flushed");
+ return Z_STREAM_END;
}
return Z_OK;
}
/* ========================================================================= */
int zlib_deflateEnd(
- z_streamp strm
+ z_streamp strm
)
{
int status;
@@ -481,7 +482,7 @@ int zlib_deflateEnd(
status = s->status;
if (status != INIT_STATE && status != BUSY_STATE &&
- status != FINISH_STATE) {
+ status != FINISH_STATE) {
return Z_STREAM_ERROR;
}
@@ -498,9 +499,9 @@ int zlib_deflateEnd(
* (See also flush_pending()).
*/
static int read_buf(
- z_streamp strm,
- Byte *buf,
- unsigned size
+ z_streamp strm,
+ Byte *buf,
+ unsigned size
)
{
unsigned len = strm->avail_in;
@@ -525,7 +526,7 @@ static int read_buf(
* Initialize the "longest match" routines for a new zlib stream
*/
static void lm_init(
- deflate_state *s
+ deflate_state *s
)
{
s->window_size = (ulg)2L*s->w_size;
@@ -560,8 +561,8 @@ static void lm_init(
* match.S. The code will be functionally equivalent.
*/
static uInt longest_match(
- deflate_state *s,
- IPos cur_match /* current match */
+ deflate_state *s,
+ IPos cur_match /* current match */
)
{
unsigned chain_length = s->max_chain_length;/* max hash chain length */
@@ -698,24 +699,81 @@ static uInt longest_match(
return s->lookahead;
}
+/* ---------------------------------------------------------------------------
+ * Optimized version for level == 1 or strategy == Z_RLE only
+ */
+static uInt longest_match_fast(
+ deflate_state *s,
+ IPos cur_match /* current match */
+)
+{
+ register Byte *scan = s->window + s->strstart; /* current string */
+ register Byte *match; /* matched string */
+ register int len; /* length of current match */
+ register Byte *strend = s->window + s->strstart + MAX_MATCH;
+
+ /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
+ * It is easy to get rid of this optimization if necessary.
+ */
+ Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
+
+ Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
+
+ Assert(cur_match < s->strstart, "no future");
+
+ match = s->window + cur_match;
+
+ /* Return failure if the match length is less than 2:
+ */
+ if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
+
+ /* The check at best_len-1 can be removed because it will be made
+ * again later. (This heuristic is not always a win.)
+ * It is not necessary to compare scan[2] and match[2] since they
+ * are always equal when the other bytes match, given that
+ * the hash keys are equal and that HASH_BITS >= 8.
+ */
+ scan += 2, match += 2;
+ Assert(*scan == *match, "match[2]?");
+
+ /* We check for insufficient lookahead only every 8th comparison;
+ * the 256th check will be made at strstart+258.
+ */
+ do {
+ } while (*++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ scan < strend);
+
+ Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
+
+ len = MAX_MATCH - (int)(strend - scan);
+
+ if (len < MIN_MATCH) return MIN_MATCH - 1;
+
+ s->match_start = cur_match;
+ return len <= s->lookahead ? len : s->lookahead;
+}
+
#ifdef DEBUG_ZLIB
/* ===========================================================================
* Check that the match at match_start is indeed a match.
*/
static void check_match(
- deflate_state *s,
- IPos start,
- IPos match,
- int length
+ deflate_state *s,
+ IPos start,
+ IPos match,
+ int length
)
{
/* check that the match is indeed a match */
if (memcmp((char *)s->window + match, (char *)s->window + start, length)) {
fprintf(stderr, " start %u, match %u, length %d\n",
- start, match, length);
+ start, match, length);
do {
- fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
- } while (--length != 0);
+ fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
+ } while (--length != 0);
z_error("invalid match");
}
if (z_verbose > 1) {
@@ -738,7 +796,7 @@ static void check_match(
* option -- not supported here).
*/
static void fill_window(
- deflate_state *s
+ deflate_state *s
)
{
register unsigned n, m;
@@ -835,8 +893,8 @@ static void fill_window(
zlib_tr_flush_block(s, (s->block_start >= 0L ? \
(char *)&s->window[(unsigned)s->block_start] : \
NULL), \
- (ulg)((long)s->strstart - s->block_start), \
- (eof)); \
+ (ulg)((long)s->strstart - s->block_start), \
+ (eof)); \
s->block_start = s->strstart; \
flush_pending(s->strm); \
Tracev((stderr,"[FLUSH]")); \
@@ -858,8 +916,8 @@ static void fill_window(
* window to pending_buf.
*/
static block_state deflate_stored(
- deflate_state *s,
- int flush
+ deflate_state *s,
+ int flush
)
{
/* Stored blocks are limited to 0xffff bytes, pending_buf is limited
@@ -878,32 +936,32 @@ static block_state deflate_stored(
if (s->lookahead <= 1) {
Assert(s->strstart < s->w_size+MAX_DIST(s) ||
- s->block_start >= (long)s->w_size, "slide too late");
+ s->block_start >= (long)s->w_size, "slide too late");
fill_window(s);
if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
if (s->lookahead == 0) break; /* flush the current block */
}
- Assert(s->block_start >= 0L, "block gone");
+ Assert(s->block_start >= 0L, "block gone");
- s->strstart += s->lookahead;
- s->lookahead = 0;
+ s->strstart += s->lookahead;
+ s->lookahead = 0;
- /* Emit a stored block if pending_buf will be full: */
- max_start = s->block_start + max_block_size;
+ /* Emit a stored block if pending_buf will be full: */
+ max_start = s->block_start + max_block_size;
if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
- /* strstart == 0 is possible when wraparound on 16-bit machine */
- s->lookahead = (uInt)(s->strstart - max_start);
- s->strstart = (uInt)max_start;
+ /* strstart == 0 is possible when wraparound on 16-bit machine */
+ s->lookahead = (uInt)(s->strstart - max_start);
+ s->strstart = (uInt)max_start;
FLUSH_BLOCK(s, 0);
- }
- /* Flush if we may have to slide, otherwise block_start may become
+ }
+ /* Flush if we may have to slide, otherwise block_start may become
* negative and the data will be gone:
*/
if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
FLUSH_BLOCK(s, 0);
- }
+ }
}
FLUSH_BLOCK(s, flush == Z_FINISH);
return flush == Z_FINISH ? finish_done : block_done;
@@ -917,8 +975,8 @@ static block_state deflate_stored(
* matches. It is used only for the fast compression options.
*/
static block_state deflate_fast(
- deflate_state *s,
- int flush
+ deflate_state *s,
+ int flush
)
{
IPos hash_head = NIL; /* head of the hash chain */
@@ -933,8 +991,8 @@ static block_state deflate_fast(
if (s->lookahead < MIN_LOOKAHEAD) {
fill_window(s);
if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
- return need_more;
- }
+ return need_more;
+ }
if (s->lookahead == 0) break; /* flush the current block */
}
@@ -953,10 +1011,12 @@ 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->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);
}
- /* longest_match() sets match_start */
+ /* longest_match() or longest_match_fast() sets match_start */
}
if (s->match_length >= MIN_MATCH) {
check_match(s, s->strstart, s->match_start, s->match_length);
@@ -979,7 +1039,7 @@ static block_state deflate_fast(
* always MIN_MATCH bytes ahead.
*/
} while (--s->match_length != 0);
- s->strstart++;
+ s->strstart++;
} else {
s->strstart += s->match_length;
s->match_length = 0;
@@ -997,7 +1057,7 @@ static block_state deflate_fast(
Tracevv((stderr,"%c", s->window[s->strstart]));
bflush = zlib_tr_tally (s, 0, s->window[s->strstart]);
s->lookahead--;
- s->strstart++;
+ s->strstart++;
}
if (bflush) FLUSH_BLOCK(s, 0);
}
@@ -1011,8 +1071,8 @@ static block_state deflate_fast(
* no better match at the next window position.
*/
static block_state deflate_slow(
- deflate_state *s,
- int flush
+ deflate_state *s,
+ int flush
)
{
IPos hash_head = NIL; /* head of hash chain */
@@ -1028,8 +1088,8 @@ static block_state deflate_slow(
if (s->lookahead < MIN_LOOKAHEAD) {
fill_window(s);
if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
- return need_more;
- }
+ return need_more;
+ }
if (s->lookahead == 0) break; /* flush the current block */
}
@@ -1051,10 +1111,12 @@ 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->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);
}
- /* longest_match() sets match_start */
+ /* longest_match() or longest_match_fast() sets match_start */
if (s->match_length <= 5 && (s->strategy == Z_FILTERED ||
(s->match_length == MIN_MATCH &&
@@ -1076,7 +1138,7 @@ static block_state deflate_slow(
check_match(s, s->strstart-1, s->prev_match, s->prev_length);
bflush = zlib_tr_tally(s, s->strstart -1 - s->prev_match,
- s->prev_length - MIN_MATCH);
+ s->prev_length - MIN_MATCH);
/* Insert in hash table all strings up to the end of the match.
* strstart-1 and strstart are already inserted. If there is not
@@ -1134,7 +1196,7 @@ int zlib_deflate_workspacesize(int windowBits, int memLevel)
/* Since the return value is typically passed to vmalloc() unchecked... */
BUG_ON(memLevel < 1 || memLevel > MAX_MEM_LEVEL || windowBits < 9 ||
- windowBits > 15);
+ windowBits > 15);
return sizeof(deflate_workspace)
+ zlib_deflate_window_memsize(windowBits)
@@ -1145,5 +1207,5 @@ int zlib_deflate_workspacesize(int windowBits, int memLevel)
int zlib_deflate_dfltcc_enabled(void)
{
- return DEFLATE_DFLTCC_ENABLED();
+ return DEFLATE_DFLTCC_ENABLED();
}
diff --git a/lib/zlib_deflate/deftree.c b/lib/zlib_deflate/deftree.c
index 2b98e56a713f..a5bcfbfe9013 100644
--- a/lib/zlib_deflate/deftree.c
+++ b/lib/zlib_deflate/deftree.c
@@ -239,7 +239,7 @@ static void tr_static_init(void)
* Initialize the tree data structures for a new zlib stream.
*/
void zlib_tr_init(
- deflate_state *s
+ deflate_state *s
)
{
tr_static_init();
@@ -270,7 +270,7 @@ void zlib_tr_init(
* Initialize a new block.
*/
static void init_block(
- deflate_state *s
+ deflate_state *s
)
{
int n; /* iterates over tree elements */
@@ -315,9 +315,9 @@ static void init_block(
* two sons).
*/
static void pqdownheap(
- deflate_state *s,
- ct_data *tree, /* the tree to restore */
- int k /* node to move down */
+ deflate_state *s,
+ ct_data *tree, /* the tree to restore */
+ int k /* node to move down */
)
{
int v = s->heap[k];
@@ -351,8 +351,8 @@ static void pqdownheap(
* not null.
*/
static void gen_bitlen(
- deflate_state *s,
- tree_desc *desc /* the tree descriptor */
+ deflate_state *s,
+ tree_desc *desc /* the tree descriptor */
)
{
ct_data *tree = desc->dyn_tree;
@@ -439,9 +439,9 @@ static void gen_bitlen(
* zero code length.
*/
static void gen_codes(
- ct_data *tree, /* the tree to decorate */
- int max_code, /* largest code with non zero frequency */
- ush *bl_count /* number of codes at each bit length */
+ ct_data *tree, /* the tree to decorate */
+ int max_code, /* largest code with non zero frequency */
+ ush *bl_count /* number of codes at each bit length */
)
{
ush next_code[MAX_BITS+1]; /* next code value for each bit length */
@@ -482,8 +482,8 @@ static void gen_codes(
* also updated if stree is not null. The field max_code is set.
*/
static void build_tree(
- deflate_state *s,
- tree_desc *desc /* the tree descriptor */
+ deflate_state *s,
+ tree_desc *desc /* the tree descriptor */
)
{
ct_data *tree = desc->dyn_tree;
@@ -571,9 +571,9 @@ static void build_tree(
* in the bit length tree.
*/
static void scan_tree(
- deflate_state *s,
- ct_data *tree, /* the tree to be scanned */
- int max_code /* and its largest code of non zero frequency */
+ deflate_state *s,
+ ct_data *tree, /* the tree to be scanned */
+ int max_code /* and its largest code of non zero frequency */
)
{
int n; /* iterates over all tree elements */
@@ -617,9 +617,9 @@ static void scan_tree(
* bl_tree.
*/
static void send_tree(
- deflate_state *s,
- ct_data *tree, /* the tree to be scanned */
- int max_code /* and its largest code of non zero frequency */
+ deflate_state *s,
+ ct_data *tree, /* the tree to be scanned */
+ int max_code /* and its largest code of non zero frequency */
)
{
int n; /* iterates over all tree elements */
@@ -669,7 +669,7 @@ static void send_tree(
* bl_order of the last bit length code to send.
*/
static int build_bl_tree(
- deflate_state *s
+ deflate_state *s
)
{
int max_blindex; /* index of last bit length code of non zero freq */
@@ -705,10 +705,10 @@ static int build_bl_tree(
* IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
*/
static void send_all_trees(
- deflate_state *s,
- int lcodes, /* number of codes for each tree */
- int dcodes, /* number of codes for each tree */
- int blcodes /* number of codes for each tree */
+ deflate_state *s,
+ int lcodes, /* number of codes for each tree */
+ int dcodes, /* number of codes for each tree */
+ int blcodes /* number of codes for each tree */
)
{
int rank; /* index in bl_order */
@@ -737,10 +737,10 @@ static void send_all_trees(
* Send a stored block
*/
void zlib_tr_stored_block(
- deflate_state *s,
- char *buf, /* input block */
- ulg stored_len, /* length of input block */
- int eof /* true if this is the last block for a file */
+ deflate_state *s,
+ char *buf, /* input block */
+ ulg stored_len, /* length of input block */
+ int eof /* true if this is the last block for a file */
)
{
send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
@@ -753,7 +753,7 @@ void zlib_tr_stored_block(
/* Send just the `stored block' type code without any length bytes or data.
*/
void zlib_tr_stored_type_only(
- deflate_state *s
+ deflate_state *s
)
{
send_bits(s, (STORED_BLOCK << 1), 3);
@@ -774,7 +774,7 @@ void zlib_tr_stored_type_only(
* on one bit only.
*/
void zlib_tr_align(
- deflate_state *s
+ deflate_state *s
)
{
send_bits(s, STATIC_TREES<<1, 3);
@@ -801,10 +801,10 @@ void zlib_tr_align(
* returns the total compressed length for the file so far.
*/
ulg zlib_tr_flush_block(
- deflate_state *s,
- char *buf, /* input block, or NULL if too old */
- ulg stored_len, /* length of input block */
- int eof /* true if this is the last block for a file */
+ deflate_state *s,
+ char *buf, /* input block, or NULL if too old */
+ ulg stored_len, /* length of input block */
+ int eof /* true if this is the last block for a file */
)
{
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
@@ -813,39 +813,39 @@ 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->data_type == Z_UNKNOWN) set_data_type(s);
+ /* Check if the file is ascii or binary */
+ if (s->data_type == Z_UNKNOWN) set_data_type(s);
- /* Construct the literal and distance trees */
- build_tree(s, (tree_desc *)(&(s->l_desc)));
- Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
- s->static_len));
+ /* Construct the literal and distance trees */
+ build_tree(s, (tree_desc *)(&(s->l_desc)));
+ Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
+ s->static_len));
- build_tree(s, (tree_desc *)(&(s->d_desc)));
- Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
- s->static_len));
- /* At this point, opt_len and static_len are the total bit lengths of
- * the compressed block data, excluding the tree representations.
- */
+ build_tree(s, (tree_desc *)(&(s->d_desc)));
+ Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
+ s->static_len));
+ /* At this point, opt_len and static_len are the total bit lengths of
+ * the compressed block data, excluding the tree representations.
+ */
- /* Build the bit length tree for the above two trees, and get the index
- * in bl_order of the last bit length code to send.
- */
- max_blindex = build_bl_tree(s);
+ /* Build the bit length tree for the above two trees, and get the index
+ * in bl_order of the last bit length code to send.
+ */
+ max_blindex = build_bl_tree(s);
- /* Determine the best encoding. Compute the block lengths in bytes. */
- opt_lenb = (s->opt_len+3+7)>>3;
- static_lenb = (s->static_len+3+7)>>3;
+ /* Determine the best encoding. Compute the block lengths in bytes. */
+ opt_lenb = (s->opt_len+3+7)>>3;
+ static_lenb = (s->static_len+3+7)>>3;
- Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
- opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
- s->last_lit));
+ Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
+ opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
+ s->last_lit));
- if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
+ if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
} else {
Assert(buf != (char*)0, "lost buf");
- opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
+ opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
}
/* If compression failed and this is the first and last block,
@@ -914,9 +914,9 @@ ulg zlib_tr_flush_block(
* the current block must be flushed.
*/
int zlib_tr_tally(
- deflate_state *s,
- unsigned dist, /* distance of matched string */
- unsigned lc /* match length-MIN_MATCH or unmatched char (if dist==0) */
+ deflate_state *s,
+ unsigned dist, /* distance of matched string */
+ unsigned lc /* match length-MIN_MATCH or unmatched char (if dist==0) */
)
{
s->d_buf[s->last_lit] = (ush)dist;
@@ -963,9 +963,9 @@ int zlib_tr_tally(
* Send the block data compressed using the given Huffman trees
*/
static void compress_block(
- deflate_state *s,
- ct_data *ltree, /* literal tree */
- ct_data *dtree /* distance tree */
+ deflate_state *s,
+ ct_data *ltree, /* literal tree */
+ ct_data *dtree /* distance tree */
)
{
unsigned dist; /* distance of matched string */
@@ -1017,7 +1017,7 @@ static void compress_block(
* frequencies does not exceed 64K (to fit in an int on 16 bit machines).
*/
static void set_data_type(
- deflate_state *s
+ deflate_state *s
)
{
int n = 0;
@@ -1034,17 +1034,17 @@ static void set_data_type(
* one's complement if requested.
*/
static void copy_block(
- deflate_state *s,
- char *buf, /* the input data */
- unsigned len, /* its length */
- int header /* true if block header must be written */
+ deflate_state *s,
+ char *buf, /* the input data */
+ unsigned len, /* its length */
+ int header /* true if block header must be written */
)
{
bi_windup(s); /* align on byte boundary */
s->last_eob_len = 8; /* enough lookahead for inflate */
if (header) {
- put_short(s, (ush)len);
+ put_short(s, (ush)len);
put_short(s, (ush)~len);
#ifdef DEBUG_ZLIB
s->bits_sent += 2*16;
diff --git a/lib/zlib_deflate/defutil.h b/lib/zlib_deflate/defutil.h
index 4ea40f5a279f..0614141d4cda 100644
--- a/lib/zlib_deflate/defutil.h
+++ b/lib/zlib_deflate/defutil.h
@@ -3,11 +3,11 @@
#include <linux/zutil.h>
-#define Assert(err, str)
-#define Trace(dummy)
-#define Tracev(dummy)
-#define Tracecv(err, dummy)
-#define Tracevv(dummy)
+#define Assert(err, str)
+#define Trace(dummy)
+#define Tracev(dummy)
+#define Tracecv(err, dummy)
+#define Tracevv(dummy)
@@ -242,17 +242,17 @@ typedef struct deflate_state {
#ifdef CONFIG_ZLIB_DFLTCC
#define zlib_deflate_window_memsize(windowBits) \
- (2 * (1 << (windowBits)) * sizeof(Byte) + PAGE_SIZE)
+ (2 * (1 << (windowBits)) * sizeof(Byte) + PAGE_SIZE)
#else
#define zlib_deflate_window_memsize(windowBits) \
- (2 * (1 << (windowBits)) * sizeof(Byte))
+ (2 * (1 << (windowBits)) * sizeof(Byte))
#endif
#define zlib_deflate_prev_memsize(windowBits) \
- ((1 << (windowBits)) * sizeof(Pos))
+ ((1 << (windowBits)) * sizeof(Pos))
#define zlib_deflate_head_memsize(memLevel) \
- ((1 << ((memLevel)+7)) * sizeof(Pos))
+ ((1 << ((memLevel)+7)) * sizeof(Pos))
#define zlib_deflate_overlay_memsize(memLevel) \
- ((1 << ((memLevel)+6)) * (sizeof(ush)+2))
+ ((1 << ((memLevel)+6)) * (sizeof(ush)+2))
/* Output a byte on the stream.
* IN assertion: there is enough room in pending_buf.
@@ -274,10 +274,10 @@ typedef struct deflate_state {
void zlib_tr_init (deflate_state *s);
int zlib_tr_tally (deflate_state *s, unsigned dist, unsigned lc);
ulg zlib_tr_flush_block (deflate_state *s, char *buf, ulg stored_len,
- int eof);
+ int eof);
void zlib_tr_align (deflate_state *s);
void zlib_tr_stored_block (deflate_state *s, char *buf, ulg stored_len,
- int eof);
+ int eof);
void zlib_tr_stored_type_only (deflate_state *);
@@ -417,7 +417,7 @@ static inline void zlib_tr_send_bits(
* (See also read_buf()).
*/
static inline void flush_pending(
- z_streamp strm
+ z_streamp strm
)
{
unsigned len;
@@ -429,8 +429,8 @@ static inline void flush_pending(
if (len == 0) return;
if (strm->next_out != NULL) {
- memcpy(strm->next_out, s->pending_out, len);
- strm->next_out += len;
+ memcpy(strm->next_out, s->pending_out, len);
+ strm->next_out += len;
}
s->pending_out += len;
strm->total_out += len;
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 05/21] lib/zlib: update deflate to zlib 1.2.0.2 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (3 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 04/21] lib/zlib: update deflate to zlib 1.2.0.1 release Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 06/21] lib/zlib: update deflate to zlib 1.2.0.3 release Greg Kroah-Hartman
` (15 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
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 <gregkh@linuxfoundation.org>
---
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 <linux/zconf.h>
-/* 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 <linux/zlib.h>
#include <linux/string.h>
@@ -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
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 06/21] lib/zlib: update deflate to zlib 1.2.0.3 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (4 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 05/21] lib/zlib: update deflate to zlib 1.2.0.2 release Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 07/21] lib/zlib: update deflate to zlib 1.2.0.4 release Greg Kroah-Hartman
` (14 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
Sync the kernel deflate code with the zlib 1.2.0.3 release.
There were no changes in the deflate code in the 1.2.0.3 release, so all
that was needed was to update the version number.
The kernel is now in sync with zlib commit 85e7d7d9ba71 ("zlib 1.2.0.3").
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/zlib.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index 64a0ceafbb2c..dce6ec967576 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -32,7 +32,7 @@
#include <linux/zconf.h>
-/* zlib deflate based on ZLIB_VERSION "1.2.0.2" */
+/* zlib deflate based on ZLIB_VERSION "1.2.0.3" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
/*
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 07/21] lib/zlib: update deflate to zlib 1.2.0.4 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (5 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 06/21] lib/zlib: update deflate to zlib 1.2.0.3 release Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 08/21] lib/zlib: update deflate to zlib 1.2.0.5 release Greg Kroah-Hartman
` (13 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
Sync the kernel deflate code with the zlib 1.2.0.4 release.
This involves:
- generalizing the noheader flag into a wrap mode (0 = raw, 1 = zlib,
2 = gzip)
- rename deflate_state.noheader to wrap and convert all users. A
finished stream now stores the negated wrap value instead of -1 so
deflateReset() can restore it.
- restructure the header and trailer emission in zlib_deflate() along
the new wrap values; a raw stream finishing with Z_FINISH returns
Z_STREAM_END directly as upstream does (any pending output has
already been flushed on the finish path or deflate would have
returned Z_OK earlier).
- carry the upstream gzip wrapper support as preprocessed-out "#ifdef
GZIP" sections. The kernel copy never defines GZIP (that would need
crc32() wired up and no kernel user produces gzip through
zlib_deflate); a note in defutil.h documents this as the upstream
NO_GZIP configuration
- comment wording updates
The kernel is now in sync with zlib commit 086e982175da ("zlib 1.2.0.4").
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/zlib.h | 2 +-
lib/zlib_deflate/deflate.c | 133 ++++++++++++++++++++++++++++++---------------
lib/zlib_deflate/defutil.h | 9 ++-
3 files changed, 97 insertions(+), 47 deletions(-)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index dce6ec967576..fd34fd3ee715 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -32,7 +32,7 @@
#include <linux/zconf.h>
-/* zlib deflate based on ZLIB_VERSION "1.2.0.3" */
+/* zlib deflate based on ZLIB_VERSION "1.2.0.4" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
/*
diff --git a/lib/zlib_deflate/deflate.c b/lib/zlib_deflate/deflate.c
index 66b4bfd260a8..7cc54a3551d7 100644
--- a/lib/zlib_deflate/deflate.c
+++ b/lib/zlib_deflate/deflate.c
@@ -136,7 +136,7 @@ typedef struct config_s {
static const config configuration_table[10] = {
/* good lazy nice chain */
/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */
-/* 1 */ {4, 4, 8, 4, deflate_fast}, /* maximum speed, no lazy matches */
+/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
/* 2 */ {4, 5, 16, 8, deflate_fast},
/* 3 */ {4, 6, 32, 32, deflate_fast},
@@ -145,7 +145,7 @@ static const config configuration_table[10] = {
/* 6 */ {8, 16, 128, 128, deflate_slow},
/* 7 */ {8, 32, 128, 256, deflate_slow},
/* 8 */ {32, 128, 258, 1024, deflate_slow},
-/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* maximum compression */
+/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */
/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
* For deflate_fast() (levels <= 3) good is ignored and lazy has a different
@@ -193,7 +193,7 @@ int zlib_deflateInit2(
)
{
deflate_state *s;
- int noheader = 0;
+ int wrap = 1;
deflate_workspace *mem;
char *next;
@@ -210,10 +210,16 @@ int zlib_deflateInit2(
mem = (deflate_workspace *) strm->workspace;
- if (windowBits < 0) { /* undocumented feature: suppress zlib header */
- noheader = 1;
+ if (windowBits < 0) { /* suppress zlib wrapper */
+ wrap = 0;
windowBits = -windowBits;
}
+#ifdef GZIP
+ else if (windowBits > 15) {
+ wrap = 2; /* write gzip wrapper instead */
+ windowBits -= 16;
+ }
+#endif
if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
strategy < 0 || strategy > Z_RLE) {
@@ -247,7 +253,7 @@ int zlib_deflateInit2(
strm->state = (struct internal_state *)s;
s->strm = strm;
- s->noheader = noheader;
+ s->wrap = wrap;
s->w_bits = windowBits;
s->w_size = 1 << s->w_bits;
s->w_mask = s->w_size - 1;
@@ -295,11 +301,15 @@ int zlib_deflateReset(
s->pending = 0;
s->pending_out = s->pending_buf;
- if (s->noheader < 0) {
- s->noheader = 0; /* was set to -1 by deflate(..., Z_FINISH); */
+ if (s->wrap < 0) {
+ s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
}
- s->status = s->noheader ? BUSY_STATE : INIT_STATE;
- strm->adler = 1;
+ s->status = s->wrap ? INIT_STATE : BUSY_STATE;
+ strm->adler =
+#ifdef GZIP
+ s->wrap == 2 ? crc32(0L, NULL, 0) :
+#endif
+ zlib_adler32(0L, NULL, 0);
s->last_flush = Z_NO_FLUSH;
zlib_tr_init(s);
@@ -349,33 +359,53 @@ int zlib_deflate(
old_flush = s->last_flush;
s->last_flush = flush;
- /* Write the zlib header */
+ /* Write the header */
if (s->status == INIT_STATE) {
-
- uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
- uInt level_flags;
+#ifdef GZIP
+ if (s->wrap == 2) {
+ put_byte(s, 31);
+ put_byte(s, 139);
+ put_byte(s, 8);
+ put_byte(s, 0);
+ put_byte(s, 0);
+ put_byte(s, 0);
+ put_byte(s, 0);
+ put_byte(s, 0);
+ put_byte(s, s->level == 9 ? 2 :
+ (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
+ 4 : 0));
+ put_byte(s, 255);
+ s->status = BUSY_STATE;
+ strm->adler = crc32(0L, NULL, 0);
+ }
+ else
+#endif
+ {
+ uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
+ uInt level_flags;
- 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);
+ 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);
- s->status = BUSY_STATE;
- putShortMSB(s, header);
+ s->status = BUSY_STATE;
+ putShortMSB(s, header);
- /* Save the adler32 of the preset dictionary: */
- if (s->strstart != 0) {
- putShortMSB(s, (uInt)(strm->adler >> 16));
- putShortMSB(s, (uInt)(strm->adler & 0xffff));
+ /* Save the adler32 of the preset dictionary: */
+ if (s->strstart != 0) {
+ putShortMSB(s, (uInt)(strm->adler >> 16));
+ putShortMSB(s, (uInt)(strm->adler & 0xffff));
+ }
+ strm->adler = zlib_adler32(0L, NULL, 0);
}
- strm->adler = 1L;
}
/* Flush as much pending output as possible */
@@ -457,9 +487,23 @@ int zlib_deflate(
Assert(strm->avail_out > 0, "bug2");
if (flush != Z_FINISH) return Z_OK;
+ if (s->wrap <= 0) return Z_STREAM_END;
- if (!s->noheader) {
- /* Write zlib trailer (adler32) */
+ /* Write the trailer */
+#ifdef GZIP
+ if (s->wrap == 2) {
+ put_byte(s, (Byte)(strm->adler & 0xff));
+ put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
+ put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
+ put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
+ put_byte(s, (Byte)(strm->total_in & 0xff));
+ put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
+ put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
+ put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
+ }
+ else
+#endif
+ {
putShortMSB(s, (uInt)(strm->adler >> 16));
putShortMSB(s, (uInt)(strm->adler & 0xffff));
}
@@ -467,14 +511,8 @@ int zlib_deflate(
/* If avail_out is zero, the application will call deflate again
* to flush the rest.
*/
- if (!s->noheader) {
- s->noheader = -1; /* write the trailer only once! */
- }
- if (s->pending == 0) {
- Assert(s->bi_valid == 0, "bi_buf not flushed");
- return Z_STREAM_END;
- }
- return Z_OK;
+ if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
+ return s->pending != 0 ? Z_OK : Z_STREAM_END;
}
/* ========================================================================= */
@@ -520,9 +558,14 @@ static int read_buf(
strm->avail_in -= len;
if (!DEFLATE_NEED_CHECKSUM(strm)) {}
- else if (!((deflate_state *)(strm->state))->noheader) {
+ else if (((deflate_state *)(strm->state))->wrap == 1) {
strm->adler = zlib_adler32(strm->adler, strm->next_in, len);
}
+#ifdef GZIP
+ else if (((deflate_state *)(strm->state))->wrap == 2) {
+ strm->adler = crc32(strm->adler, strm->next_in, len);
+ }
+#endif
memcpy(buf, strm->next_in, len);
strm->next_in += len;
strm->total_in += len;
@@ -822,7 +865,7 @@ static void fill_window(
} else if (more == (unsigned)(-1)) {
/* Very unlikely, but possible on 16 bit machine if
- * strstart == 0 && lookahead == 1 (input done one byte at time)
+ * strstart == 0 && lookahead == 1 (input done a byte at time)
*/
more--;
}
@@ -1042,7 +1085,7 @@ static block_state deflate_fast(
*/
if (s->match_length <= s->max_insert_length &&
s->lookahead >= MIN_MATCH) {
- s->match_length--; /* string at strstart already in hash table */
+ s->match_length--; /* string at strstart already in table */
do {
s->strstart++;
INSERT_STRING(s, s->strstart, hash_head);
diff --git a/lib/zlib_deflate/defutil.h b/lib/zlib_deflate/defutil.h
index 0614141d4cda..dec377b7d25c 100644
--- a/lib/zlib_deflate/defutil.h
+++ b/lib/zlib_deflate/defutil.h
@@ -3,6 +3,13 @@
#include <linux/zutil.h>
+/* define NO_GZIP when compiling if you want to disable gzip header and
+ trailer creation by deflate(). NO_GZIP would be used to avoid linking in
+ the crc code when it is not needed. For shared libraries, gzip encoding
+ should be left enabled.
+ The kernel copy does not provide crc32() to this code, so GZIP is never
+ defined here: the kernel always builds the NO_GZIP variant. */
+
#define Assert(err, str)
#define Trace(dummy)
#define Tracev(dummy)
@@ -77,7 +84,7 @@ typedef struct deflate_state {
ulg pending_buf_size; /* size of pending_buf */
Byte *pending_out; /* next pending byte to output to the stream */
int pending; /* nb of bytes in the pending buffer */
- int noheader; /* suppress zlib header and adler32 */
+ int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
Byte data_type; /* UNKNOWN, BINARY or ASCII */
Byte method; /* STORED (for zip only) or DEFLATED */
int last_flush; /* value of flush param for previous deflate call */
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 08/21] lib/zlib: update deflate to zlib 1.2.0.5 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (6 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 07/21] lib/zlib: update deflate to zlib 1.2.0.4 release Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 09/21] lib/zlib: update deflate to zlib 1.2.0.6 release Greg Kroah-Hartman
` (12 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
Sync the kernel deflate code with the zlib 1.2.0.5 release.
This involves:
- reorder the INSERT_STRING() assignment so match_head is assigned
from the chained store rather than relying on the evaluation order
of s->prev[...] = match_head = s->head[...]: when str aliases the
head slot's chain this reads more clearly and avoids a sequencing
surprise on exotic compilers, which the kernel really doesn't need
to worry about at all, our compilers are anything but exotic,
fortunatly.
- change the TOO_FAR guard from "< 32768" to "<= 32767" to avoid an
overflowing constant comparison on 16-bit ints.
- comment case fix in zutil.h
There were some 1.2.0.5 changes that were not relevant to the kernel
copy:
- alloc_func/free_func cast changes.
- OS_CODE table reshuffle.
The kernel is now in sync with zlib commit 4b5a43a219d5 ("zlib 1.2.0.5").
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/zlib.h | 2 +-
include/linux/zutil.h | 2 +-
lib/zlib_deflate/deflate.c | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index fd34fd3ee715..5e6b5ed3766e 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -32,7 +32,7 @@
#include <linux/zconf.h>
-/* zlib deflate based on ZLIB_VERSION "1.2.0.4" */
+/* zlib deflate based on ZLIB_VERSION "1.2.0.5" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
/*
diff --git a/include/linux/zutil.h b/include/linux/zutil.h
index 2197ac6cff70..4032cfc1e82b 100644
--- a/include/linux/zutil.h
+++ b/include/linux/zutil.h
@@ -36,7 +36,7 @@ typedef unsigned long ulg;
/* target dependencies */
- /* Common defaults */
+ /* common defaults */
#ifndef OS_CODE
# define OS_CODE 0x03 /* assume Unix */
diff --git a/lib/zlib_deflate/deflate.c b/lib/zlib_deflate/deflate.c
index 7cc54a3551d7..cb221eab7aa6 100644
--- a/lib/zlib_deflate/deflate.c
+++ b/lib/zlib_deflate/deflate.c
@@ -171,7 +171,7 @@ static const config configuration_table[10] = {
*/
#define INSERT_STRING(s, str, match_head) \
(UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
- s->prev[(str) & s->w_mask] = match_head = s->head[s->ins_h], \
+ match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
s->head[s->ins_h] = (Pos)(str))
/* ===========================================================================
@@ -1173,7 +1173,7 @@ static block_state deflate_slow(
/* longest_match() or longest_match_fast() sets match_start */
if (s->match_length <= 5 && (s->strategy == Z_FILTERED
-#if TOO_FAR < 32768
+#if TOO_FAR <= 32767
|| (s->match_length == MIN_MATCH &&
s->strstart - s->match_start > TOO_FAR)
#endif
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 09/21] lib/zlib: update deflate to zlib 1.2.0.6 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (7 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 08/21] lib/zlib: update deflate to zlib 1.2.0.5 release Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 10/21] lib/zlib: update deflate to zlib 1.2.0.7 release Greg Kroah-Hartman
` (11 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
Sync the kernel deflate code with the zlib 1.2.0.6 release.
There were no changes in the deflate code in the 1.2.0.3 release, so all
that was needed was to update the version number.
The kernel is now in sync with zlib commit f81ba93d4a7e ("zlib 1.2.0.6").
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/zlib.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index 5e6b5ed3766e..36c4c103e241 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -32,7 +32,7 @@
#include <linux/zconf.h>
-/* zlib deflate based on ZLIB_VERSION "1.2.0.5" */
+/* zlib deflate based on ZLIB_VERSION "1.2.0.6" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
/*
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 10/21] lib/zlib: update deflate to zlib 1.2.0.7 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (8 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 09/21] lib/zlib: update deflate to zlib 1.2.0.6 release Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 11/21] lib/zlib: update deflate to zlib 1.2.0.8 release Greg Kroah-Hartman
` (10 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
Sync the kernel deflate code with the zlib 1.2.0.7 release.
Only one change was "needed", other than the version string update:
- Cast s->pending to uInt in the compress_block() overlay assertion so
the signed/unsigned comparison is well defined when assertions are
compiled in. In reality, this isn't needed for us as we compile all
Assert() calls out in the kernel, so there's no change at all.
There was one 1.2.0.7 change that wasn't relevant to the kernel copy:
- vsnprintf detection.
The kernel is now in sync with zlib commit b97ec631c6f7 ("zlib 1.2.0.7").
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/zlib.h | 2 +-
lib/zlib_deflate/deftree.c | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index 36c4c103e241..fbc88c5e3721 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -32,7 +32,7 @@
#include <linux/zconf.h>
-/* zlib deflate based on ZLIB_VERSION "1.2.0.6" */
+/* zlib deflate based on ZLIB_VERSION "1.2.0.7" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
/*
diff --git a/lib/zlib_deflate/deftree.c b/lib/zlib_deflate/deftree.c
index a5bcfbfe9013..2eaf8264cc33 100644
--- a/lib/zlib_deflate/deftree.c
+++ b/lib/zlib_deflate/deftree.c
@@ -1002,7 +1002,8 @@ static void compress_block(
} /* literal or match pair ? */
/* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
- Assert(s->pending < s->lit_bufsize + 2*lx, "pendingBuf overflow");
+ Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
+ "pendingBuf overflow");
} while (lx < s->last_lit);
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 11/21] lib/zlib: update deflate to zlib 1.2.0.8 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (9 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 10/21] lib/zlib: update deflate to zlib 1.2.0.7 release Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 12/21] lib/zlib: update deflate to zlib 1.2.1 release Greg Kroah-Hartman
` (9 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
Sync the kernel deflate code with the zlib 1.2.0.8 release.
There were no changes in the deflate code in the 1.2.0.8 relevent to the
kernel, so all that was needed was to update the version number.
There was one 1.2.0.8 change that wasn't relevant to the kernel copy:
- added deflatePrime() to the deflate code, but we never need to
insert bits ahead of a deflate stream, so no need to worry about
this one.
The kernel is now in sync with zlib commit a2506218cd8c ("zlib 1.2.0.8").
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/zlib.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index fbc88c5e3721..e424b2e43abe 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -32,7 +32,7 @@
#include <linux/zconf.h>
-/* zlib deflate based on ZLIB_VERSION "1.2.0.7" */
+/* zlib deflate based on ZLIB_VERSION "1.2.0.8" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
/*
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 12/21] lib/zlib: update deflate to zlib 1.2.1 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (10 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 11/21] lib/zlib: update deflate to zlib 1.2.0.8 release Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 13/21] lib/zlib: update deflate to zlib 1.2.1.1 release Greg Kroah-Hartman
` (8 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
Sync the kernel deflate code with the zlib 1.2.1 release.
There were no changes in the deflate code in the 1.2.1 relevent to the
kernel, so all that was needed was to update the version number.
There was one 1.2.1 change that wasn't relevant to the kernel copy:
- the WinCE ptrdiff_t define in zutil.h, which we don't care about.
The kernel is now in sync with zlib commit 7a33a861d152 ("zlib 1.2.1").
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/zlib.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index e424b2e43abe..263463c5e3f2 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -32,7 +32,7 @@
#include <linux/zconf.h>
-/* zlib deflate based on ZLIB_VERSION "1.2.0.8" */
+/* zlib deflate based on ZLIB_VERSION "1.2.1" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
/*
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 13/21] lib/zlib: update deflate to zlib 1.2.1.1 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (11 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 12/21] lib/zlib: update deflate to zlib 1.2.1 release Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 14/21] lib/zlib: update deflate to zlib 1.2.1.2 release Greg Kroah-Hartman
` (7 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
Sync the kernel deflate code with the zlib 1.2.1.1 release.
There were no changes in the deflate code in the 1.2.1.1 relevent to the
kernel, so all that was needed was to update the version number.
The kernel is now in sync with zlib commit f0e76a6634eb ("zlib 1.2.1.1").
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/zlib.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index 263463c5e3f2..2419cbc1e08f 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -32,7 +32,7 @@
#include <linux/zconf.h>
-/* zlib deflate based on ZLIB_VERSION "1.2.1" */
+/* zlib deflate based on ZLIB_VERSION "1.2.1.1" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
/*
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 14/21] lib/zlib: update deflate to zlib 1.2.1.2 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (12 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 13/21] lib/zlib: update deflate to zlib 1.2.1.1 release Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 15/21] lib/zlib: update deflate to zlib 1.2.2 release Greg Kroah-Hartman
` (6 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
Sync the kernel deflate code with the zlib 1.2.1.2 release.
Only one change was "needed", other than the version string update:
- Drop the data_type field from the deflate state and set the data
type guess directly in z_stream.data_type.
There was one 1.2.1.2 change that wasn't relevant to the kernel copy:
- VMS vsnprintf/strerror handling.
The kernel is now in sync with zlib commit 7a6955760ba9 ("zlib 1.2.1.2").
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/zlib.h | 2 +-
lib/zlib_deflate/deflate.c | 2 +-
lib/zlib_deflate/deftree.c | 4 ++--
lib/zlib_deflate/defutil.h | 1 -
4 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index 2419cbc1e08f..2dbc3aec1f81 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -32,7 +32,7 @@
#include <linux/zconf.h>
-/* zlib deflate based on ZLIB_VERSION "1.2.1.1" */
+/* zlib deflate based on ZLIB_VERSION "1.2.1.2" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
/*
diff --git a/lib/zlib_deflate/deflate.c b/lib/zlib_deflate/deflate.c
index cb221eab7aa6..d6d29f63b572 100644
--- a/lib/zlib_deflate/deflate.c
+++ b/lib/zlib_deflate/deflate.c
@@ -1,6 +1,6 @@
/* +++ deflate.c */
/* deflate.c -- compress data using the deflation algorithm
- * 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 2eaf8264cc33..dbe0eda9a824 100644
--- a/lib/zlib_deflate/deftree.c
+++ b/lib/zlib_deflate/deftree.c
@@ -814,7 +814,7 @@ ulg zlib_tr_flush_block(
if (s->level > 0) {
/* Check if the file is ascii or binary */
- if (s->data_type == Z_UNKNOWN) set_data_type(s);
+ if (s->strm->data_type == Z_UNKNOWN) set_data_type(s);
/* Construct the literal and distance trees */
build_tree(s, (tree_desc *)(&(s->l_desc)));
@@ -1027,7 +1027,7 @@ static void set_data_type(
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->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII);
+ s->strm->data_type = bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII;
}
/* ===========================================================================
diff --git a/lib/zlib_deflate/defutil.h b/lib/zlib_deflate/defutil.h
index dec377b7d25c..b639235c4fa6 100644
--- a/lib/zlib_deflate/defutil.h
+++ b/lib/zlib_deflate/defutil.h
@@ -85,7 +85,6 @@ typedef struct deflate_state {
Byte *pending_out; /* next pending byte to output to the stream */
int pending; /* nb of bytes in the pending buffer */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
- Byte data_type; /* UNKNOWN, BINARY or ASCII */
Byte method; /* STORED (for zip only) or DEFLATED */
int last_flush; /* value of flush param for previous deflate call */
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 15/21] lib/zlib: update deflate to zlib 1.2.2 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (13 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 14/21] lib/zlib: update deflate to zlib 1.2.1.2 release Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 16/21] lib/zlib: update deflate to zlib 1.2.2.1 release Greg Kroah-Hartman
` (5 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
Sync the kernel deflate code with the zlib 1.2.2 release.
There were no changes in the deflate code in the 1.2.2 relevent to the
kernel, so all that was needed was to update the version number.
The kernel is now in sync with zlib commit 79fbcdc939b5 ("zlib 1.2.2").
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/zlib.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index 2dbc3aec1f81..aa566d10364c 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -32,7 +32,7 @@
#include <linux/zconf.h>
-/* zlib deflate based on ZLIB_VERSION "1.2.1.2" */
+/* zlib deflate based on ZLIB_VERSION "1.2.2" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
/*
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 16/21] lib/zlib: update deflate to zlib 1.2.2.1 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (14 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 15/21] lib/zlib: update deflate to zlib 1.2.2 release Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 17/21] lib/zlib: catch code up to the real zlib 1.1.3 Greg Kroah-Hartman
` (4 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
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 <gregkh@linuxfoundation.org>
---
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 <linux/zconf.h>
-/* 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
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 17/21] lib/zlib: catch code up to the real zlib 1.1.3
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (15 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 16/21] lib/zlib: update deflate to zlib 1.2.2.1 release Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 18/21] lib/zlib: update deflate to zlib 1.2.2.2 release Greg Kroah-Hartman
` (3 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
Despite the kernel code claiming to be newer, there are two parts of the
deflate code that were older than the 1.1.3 version. Fix this up so
that future deflate changes will apply properly:
- the compressed_len accounting is a debug-only change as it is only
ever read inside DEBUG tracing.
- remove the dead #ifdef STORED_FILE_OK block in zlib_tr_flush_block()
The kernel is now in sync with zlib commit 14763ac7c6c0 ("zlib 1.1.3"),
for real this time.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
lib/zlib_deflate/deftree.c | 41 ++++++++++++++++-------------------------
lib/zlib_deflate/defutil.h | 2 +-
2 files changed, 17 insertions(+), 26 deletions(-)
diff --git a/lib/zlib_deflate/deftree.c b/lib/zlib_deflate/deftree.c
index d4107392d70c..baa8d37fd094 100644
--- a/lib/zlib_deflate/deftree.c
+++ b/lib/zlib_deflate/deftree.c
@@ -244,8 +244,6 @@ void zlib_tr_init(
{
tr_static_init();
- s->compressed_len = 0L;
-
s->l_desc.dyn_tree = s->dyn_ltree;
s->l_desc.stat_desc = &static_l_desc;
@@ -259,6 +257,7 @@ void zlib_tr_init(
s->bi_valid = 0;
s->last_eob_len = 8; /* enough lookahead for inflate */
#ifdef DEBUG_ZLIB
+ s->compressed_len = 0L;
s->bits_sent = 0L;
#endif
@@ -744,9 +743,10 @@ void zlib_tr_stored_block(
)
{
send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
+#ifdef DEBUG_ZLIB
s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
s->compressed_len += (stored_len + 4) << 3;
-
+#endif
copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
}
@@ -758,7 +758,9 @@ void zlib_tr_stored_type_only(
{
send_bits(s, (STORED_BLOCK << 1), 3);
bi_windup(s);
+#ifdef DEBUG_ZLIB
s->compressed_len = (s->compressed_len + 3) & ~7L;
+#endif
}
@@ -779,7 +781,9 @@ void zlib_tr_align(
{
send_bits(s, STATIC_TREES<<1, 3);
send_code(s, END_BLOCK, static_ltree);
+#ifdef DEBUG_ZLIB
s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
+#endif
bi_flush(s);
/* Of the 10 bits for the empty block, we have already sent
* (10 - bi_valid) bits. The lookahead for the last real code (before
@@ -789,7 +793,9 @@ void zlib_tr_align(
if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
send_bits(s, STATIC_TREES<<1, 3);
send_code(s, END_BLOCK, static_ltree);
+#ifdef DEBUG_ZLIB
s->compressed_len += 10L;
+#endif
bi_flush(s);
}
s->last_eob_len = 7;
@@ -800,7 +806,7 @@ void zlib_tr_align(
* trees or store, and output the encoded block to the zip file. This function
* returns the total compressed length for the file so far.
*/
-ulg zlib_tr_flush_block(
+void zlib_tr_flush_block(
deflate_state *s,
char *buf, /* input block, or NULL if too old */
ulg stored_len, /* length of input block */
@@ -849,25 +855,6 @@ ulg zlib_tr_flush_block(
opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
}
- /* If compression failed and this is the first and last block,
- * and if the .zip file can be seeked (to rewrite the local header),
- * the whole file is transformed into a stored file:
- */
-#ifdef STORED_FILE_OK
-# ifdef FORCE_STORED_FILE
- if (eof && s->compressed_len == 0L) { /* force stored file */
-# else
- if (stored_len <= opt_lenb && eof && s->compressed_len==0L && seekable()) {
-# endif
- /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
- if (buf == (char*)0) error ("block vanished");
-
- copy_block(s, buf, (unsigned)stored_len, 0); /* without header */
- s->compressed_len = stored_len << 3;
- s->method = STORED;
- } else
-#endif /* STORED_FILE_OK */
-
#ifdef FORCE_STORED
if (buf != (char*)0) { /* force stored block */
#else
@@ -889,25 +876,29 @@ ulg zlib_tr_flush_block(
#endif
send_bits(s, (STATIC_TREES<<1)+eof, 3);
compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
+#ifdef DEBUG_ZLIB
s->compressed_len += 3 + s->static_len;
+#endif
} else {
send_bits(s, (DYN_TREES<<1)+eof, 3);
send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
max_blindex+1);
compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
+#ifdef DEBUG_ZLIB
s->compressed_len += 3 + s->opt_len;
+#endif
}
Assert (s->compressed_len == s->bits_sent, "bad compressed size");
init_block(s);
if (eof) {
bi_windup(s);
+#ifdef DEBUG_ZLIB
s->compressed_len += 7; /* align on byte boundary */
+#endif
}
Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
s->compressed_len-7*eof));
-
- return s->compressed_len >> 3;
}
/* ===========================================================================
diff --git a/lib/zlib_deflate/defutil.h b/lib/zlib_deflate/defutil.h
index b639235c4fa6..29fa51e32da1 100644
--- a/lib/zlib_deflate/defutil.h
+++ b/lib/zlib_deflate/defutil.h
@@ -279,7 +279,7 @@ typedef struct deflate_state {
/* in trees.c */
void zlib_tr_init (deflate_state *s);
int zlib_tr_tally (deflate_state *s, unsigned dist, unsigned lc);
-ulg zlib_tr_flush_block (deflate_state *s, char *buf, ulg stored_len,
+void zlib_tr_flush_block (deflate_state *s, char *buf, ulg stored_len,
int eof);
void zlib_tr_align (deflate_state *s);
void zlib_tr_stored_block (deflate_state *s, char *buf, ulg stored_len,
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 18/21] lib/zlib: update deflate to zlib 1.2.2.2 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (16 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 17/21] lib/zlib: catch code up to the real zlib 1.1.3 Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 19/21] lib/zlib: update deflate to zlib 1.2.2.3 release Greg Kroah-Hartman
` (2 subsequent siblings)
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
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 <gregkh@linuxfoundation.org>
---
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 <linux/zconf.h>
-/* 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
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 19/21] lib/zlib: update deflate to zlib 1.2.2.3 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (17 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 18/21] lib/zlib: update deflate to zlib 1.2.2.2 release Greg Kroah-Hartman
@ 2026-12-03 7:29 ` Greg Kroah-Hartman
2026-12-03 7:30 ` [PATCH 20/21] lib/zlib: update deflate to zlib 1.2.2.4 release Greg Kroah-Hartman
2026-12-03 7:30 ` [PATCH 21/21] lib/zlib: update deflate to zlib 1.2.3 release Greg Kroah-Hartman
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:29 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
Sync the kernel deflate code with the zlib 1.2.2.3 release.
There was no needed changes relevant for the kernel copy, so just update
the copyright year and the version number.
The unneeded changes were:
- added deflateTune()
- dropped the USE_DICT_HEAD variant of deflateSetDictionary()
but both of them are not in the kernel copy, so not an issue.
The kernel is now in sync with zlib commit 6b8233bfe00e ("zlib 1.2.2.3").
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/zlib.h | 2 +-
include/linux/zutil.h | 2 +-
lib/zlib_deflate/deflate.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index 95d90b51970c..2220e8f4bc12 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -32,7 +32,7 @@
#include <linux/zconf.h>
-/* zlib deflate based on ZLIB_VERSION "1.2.2.2" */
+/* zlib deflate based on ZLIB_VERSION "1.2.2.3" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
/*
diff --git a/include/linux/zutil.h b/include/linux/zutil.h
index 3ad9a50e3e89..f55070c7b90d 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-2004 Jean-loup Gailly.
+ * Copyright (C) 1995-2005 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
diff --git a/lib/zlib_deflate/deflate.c b/lib/zlib_deflate/deflate.c
index f7ff13a15434..b2c8860d6591 100644
--- a/lib/zlib_deflate/deflate.c
+++ b/lib/zlib_deflate/deflate.c
@@ -1,6 +1,6 @@
/* +++ deflate.c */
/* deflate.c -- compress data using the deflation algorithm
- * Copyright (C) 1995-2004 Jean-loup Gailly.
+ * Copyright (C) 1995-2005 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 20/21] lib/zlib: update deflate to zlib 1.2.2.4 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (18 preceding siblings ...)
2026-12-03 7:29 ` [PATCH 19/21] lib/zlib: update deflate to zlib 1.2.2.3 release Greg Kroah-Hartman
@ 2026-12-03 7:30 ` Greg Kroah-Hartman
2026-12-03 7:30 ` [PATCH 21/21] lib/zlib: update deflate to zlib 1.2.3 release Greg Kroah-Hartman
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:30 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
Bring the kernel deflate code up to zlib 1.2.2.4:
This involves:
- make deflate_state.pending unsigned (uInt), it's a byte count that
is compared against unsigned sizes everywhere.
- cast tree[m].Len explicitly in the gen_bitlen() comparison
- copy upstream's #if 0 draft of deflate_rle() (enabled in a later
release) with kernel-style tally calls
- fill_window() %%% marker comment
Changes that were not relevant for our copy were the gzip header
put_byte casts and gzindex type change as they are in code that the
kernel didn't ever copy.
The kernel is now in sync with zlib commit 9c3a5830218c ("zlib 1.2.2.4").
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/zlib.h | 2 +-
lib/zlib_deflate/deflate.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++
lib/zlib_deflate/deftree.c | 4 +--
lib/zlib_deflate/defutil.h | 2 +-
4 files changed, 67 insertions(+), 4 deletions(-)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index 2220e8f4bc12..5ceb476f959c 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -32,7 +32,7 @@
#include <linux/zconf.h>
-/* zlib deflate based on ZLIB_VERSION "1.2.2.3" */
+/* zlib deflate based on ZLIB_VERSION "1.2.2.4" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
/*
diff --git a/lib/zlib_deflate/deflate.c b/lib/zlib_deflate/deflate.c
index b2c8860d6591..26b934eb84d3 100644
--- a/lib/zlib_deflate/deflate.c
+++ b/lib/zlib_deflate/deflate.c
@@ -893,6 +893,7 @@ static void fill_window(
later. (Using level 0 permanently is not an optimal usage of
zlib, so we don't care about this pathological case.)
*/
+ /* %%% avoid this when Z_RLE */
n = s->hash_size;
p = &s->head[n];
do {
@@ -1251,6 +1252,68 @@ static block_state deflate_slow(
return flush == Z_FINISH ? finish_done : block_done;
}
+#if 0
+/* ===========================================================================
+ * For Z_RLE, simply look for runs of bytes, generate matches only of distance
+ * one. Do not maintain a hash table. (It will be regenerated if this run of
+ * deflate switches away from Z_RLE.)
+ */
+static block_state deflate_rle(
+ deflate_state *s,
+ int flush
+)
+{
+ int bflush; /* set if current block must be flushed */
+ uInt run; /* length of run */
+ uInt max; /* maximum length of run */
+ uInt prev; /* byte at distance one to match */
+ Byte *scan; /* scan for end of run */
+
+ for (;;) {
+ /* Make sure that we always have enough lookahead, except
+ * at the end of the input file. We need MAX_MATCH bytes
+ * for the longest encodable run.
+ */
+ if (s->lookahead < MAX_MATCH) {
+ fill_window(s);
+ if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
+ return need_more;
+ }
+ if (s->lookahead == 0) break; /* flush the current block */
+ }
+
+ /* See how many times the previous byte repeats */
+ run = 0;
+ if (s->strstart > 0) { /* if there is a previous byte, that is */
+ max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
+ scan = s->window + s->strstart - 1;
+ prev = *scan++;
+ do {
+ if (*scan++ != prev)
+ break;
+ } while (++run < max);
+ }
+
+ /* Emit match if have run of MIN_MATCH or longer, else emit literal */
+ if (run >= MIN_MATCH) {
+ check_match(s, s->strstart, s->strstart - 1, run);
+ bflush = zlib_tr_tally(s, 1, run - MIN_MATCH);
+ s->lookahead -= run;
+ s->strstart += run;
+ } else {
+ /* No match, output a literal byte */
+ Tracevv((stderr,"%c", s->window[s->strstart]));
+ bflush = zlib_tr_tally (s, 0, s->window[s->strstart]);
+ s->lookahead--;
+ s->strstart++;
+ }
+ if (bflush) FLUSH_BLOCK(s, 0);
+ }
+ FLUSH_BLOCK(s, flush == Z_FINISH);
+ return flush == Z_FINISH ? finish_done : block_done;
+}
+#endif
+
int zlib_deflate_workspacesize(int windowBits, int memLevel)
{
if (windowBits < 0) /* undocumented feature: suppress zlib header */
diff --git a/lib/zlib_deflate/deftree.c b/lib/zlib_deflate/deftree.c
index b98feac2d498..2ae58d219155 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-2004 Jean-loup Gailly
+ * Copyright (C) 1995-2005 Jean-loup Gailly
* For conditions of distribution and use, see copyright notice in zlib.h
*/
@@ -418,7 +418,7 @@ static void gen_bitlen(
while (n != 0) {
m = s->heap[--h];
if (m > max_code) continue;
- if (tree[m].Len != (unsigned) bits) {
+ if ((unsigned) tree[m].Len != (unsigned) bits) {
Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
s->opt_len += ((long)bits - (long)tree[m].Len)
*(long)tree[m].Freq;
diff --git a/lib/zlib_deflate/defutil.h b/lib/zlib_deflate/defutil.h
index 29fa51e32da1..98713d1b3f58 100644
--- a/lib/zlib_deflate/defutil.h
+++ b/lib/zlib_deflate/defutil.h
@@ -83,7 +83,7 @@ typedef struct deflate_state {
Byte *pending_buf; /* output still pending */
ulg pending_buf_size; /* size of pending_buf */
Byte *pending_out; /* next pending byte to output to the stream */
- int pending; /* nb of bytes in the pending buffer */
+ uInt pending; /* nb of bytes in the pending buffer */
int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
Byte method; /* STORED (for zip only) or DEFLATED */
int last_flush; /* value of flush param for previous deflate call */
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 21/21] lib/zlib: update deflate to zlib 1.2.3 release
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
` (19 preceding siblings ...)
2026-12-03 7:30 ` [PATCH 20/21] lib/zlib: update deflate to zlib 1.2.2.4 release Greg Kroah-Hartman
@ 2026-12-03 7:30 ` Greg Kroah-Hartman
20 siblings, 0 replies; 22+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-03 7:30 UTC (permalink / raw)
To: linux-kernel, Greg Kroah-Hartman
Sync the kernel deflate code with the zlib 1.2.3 release.
There were no changes in the deflate code in the 1.2.3 relevant to the
kernel, so all that was needed was to update the version number.
The kernel is now in sync with zlib commit abf180a06722 ("zlib 1.2.3").
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/zlib.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index 5ceb476f959c..1093faf1bd16 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -32,7 +32,7 @@
#include <linux/zconf.h>
-/* zlib deflate based on ZLIB_VERSION "1.2.2.4" */
+/* zlib deflate based on ZLIB_VERSION "1.2.3" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
/*
--
2.56.1
^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2026-12-03 7:32 UTC | newest]
Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-03 7:29 [PATCH 00/21] lib/zlib: start to bring the in-kernel version in sync with upstream Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 01/21] MAINTAINERS: add myself as the zlib maintainer Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 02/21] lib/zlib: update deflate to zlib 1.1.4 release Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 03/21] lib/zlib: update deflate to zlib 1.2.0 release Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 04/21] lib/zlib: update deflate to zlib 1.2.0.1 release Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 05/21] lib/zlib: update deflate to zlib 1.2.0.2 release Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 06/21] lib/zlib: update deflate to zlib 1.2.0.3 release Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 07/21] lib/zlib: update deflate to zlib 1.2.0.4 release Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 08/21] lib/zlib: update deflate to zlib 1.2.0.5 release Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 09/21] lib/zlib: update deflate to zlib 1.2.0.6 release Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 10/21] lib/zlib: update deflate to zlib 1.2.0.7 release Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 11/21] lib/zlib: update deflate to zlib 1.2.0.8 release Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 12/21] lib/zlib: update deflate to zlib 1.2.1 release Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 13/21] lib/zlib: update deflate to zlib 1.2.1.1 release Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 14/21] lib/zlib: update deflate to zlib 1.2.1.2 release Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 15/21] lib/zlib: update deflate to zlib 1.2.2 release Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 16/21] lib/zlib: update deflate to zlib 1.2.2.1 release Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 17/21] lib/zlib: catch code up to the real zlib 1.1.3 Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 18/21] lib/zlib: update deflate to zlib 1.2.2.2 release Greg Kroah-Hartman
2026-12-03 7:29 ` [PATCH 19/21] lib/zlib: update deflate to zlib 1.2.2.3 release Greg Kroah-Hartman
2026-12-03 7:30 ` [PATCH 20/21] lib/zlib: update deflate to zlib 1.2.2.4 release Greg Kroah-Hartman
2026-12-03 7:30 ` [PATCH 21/21] lib/zlib: update deflate to zlib 1.2.3 release Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®