]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Fix bug in block type selection when Z_FIXED used.
authorMark Adler <fork@madler.net>
Sun, 2 Oct 2022 02:55:29 +0000 (19:55 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 17 Mar 2023 20:27:56 +0000 (21:27 +0100)
A fixed block could be chosen when a stored block was smaller. Now
the smaller of the two is always chosen.

trees.c

diff --git a/trees.c b/trees.c
index c3d484950d0024cf1e3fbb7cd9c3a0a40cc15c31..996578874e9b2aabf415a6ca145f40e2b2e41141 100644 (file)
--- a/trees.c
+++ b/trees.c
@@ -670,7 +670,7 @@ void Z_INTERNAL zng_tr_flush_block(deflate_state *s, char *buf, uint32_t stored_
                 opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
                 s->sym_next / 3));
 
-        if (static_lenb <= opt_lenb)
+        if (static_lenb <= opt_lenb || s->strategy == Z_FIXED)
             opt_lenb = static_lenb;
 
     } else {
@@ -688,7 +688,7 @@ void Z_INTERNAL zng_tr_flush_block(deflate_state *s, char *buf, uint32_t stored_
          */
         zng_tr_stored_block(s, buf, stored_len, last);
 
-    } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
+    } else if (static_lenb == opt_lenb) {
         zng_tr_emit_tree(s, STATIC_TREES, last);
         compress_block(s, (const ct_data *)static_ltree, (const ct_data *)static_dtree);
         cmpr_bits_add(s, s->static_len);