[PATCH 17/21] lib/zlib: catch code up to the real zlib 1.1.3
From: Greg Kroah-Hartman
Date: Thu Dec 03 2026 - 02:32:13 EST
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@xxxxxxxxxxxxxxxxxxx>
---
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