mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 17/21] lib/zlib: catch code up to the real zlib 1.1.3
Date: Thu, 03 Dec 2026 08:29:57 +0100	[thread overview]
Message-ID: <20261203-zlib-sync-v1-17-0d4ec56f1afb@linuxfoundation.org> (raw)
In-Reply-To: <20261203-zlib-sync-v1-0-0d4ec56f1afb@linuxfoundation.org>

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


  parent reply	other threads:[~2026-12-03  7:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Greg Kroah-Hartman [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203-zlib-sync-v1-17-0d4ec56f1afb@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®