From 4acdc86b10df36acd76370337be4e66aa3d9b180 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Fri, 24 Jul 2026 23:15:13 -0700
Subject: [PATCH] gzip: don't mishandle .lzh after .Z (better fix)

* unlzh.c (read_c_len): Move clearing of left and right from here ...
(huf_decode_start): ... to here.
Problem and fix reported by Elias Hasas.

Index: b/THANKS
===================================================================
--- a/THANKS
+++ b/THANKS
@@ -81,6 +81,7 @@ John Eaton              jwe@che.utexas.e
 Will Edgington          wedgingt@ptolemy.arc.nasa.gov
 Brian Edmonds           edmonds@edmonds.home.cs.ubc.ca
 Paul Eggert             eggert@cs.ucla.edu
+Elias Hasas		ehasas17@outlook.com
 Enami                   enami@sys.ptg.sony.co.jp
 Kristoffer Eriksson     ske@pkmab.se
 Daniel Eriksson         m91der@bellatrix.tdb.uu.se
@@ -186,6 +187,7 @@ Jamie Lokier            u90jl@ecs.oxford
 Richard Lloyd           R.K.Lloyd@csc.liv.ac.uk
 David J. MacKenzie	djm@eng.umd.edu
 John R MacMillan        john@chance.gts.org
+Michał Majchrowicz	mmajchrowicz@afine.com
 Ron Male                male@eso.mc.xerox.com
 Jakub Martisko		jamartis@redhat.com
 Don R. Maszle           maze@bea.lbl.gov
Index: b/unlzh.c
===================================================================
--- a/unlzh.c
+++ b/unlzh.c
@@ -314,6 +314,12 @@ decode_p ()
 static void
 huf_decode_start ()
 {
+    /* Needed in case LEFT and RIGHT are reused from a previous
+       LZW decompression.  It may be overkill to clear all of both
+       arrays, but nobody has had time to analyze this carefully.  */
+    memzero (left, (2 * NC - 1) * sizeof *left);
+    memzero (right, (2 * NC - 1) * sizeof *right);
+
     init_getbits();  blocksize = 0;
 }
 
