From: Tobias Stoeckmann Date: Mon, 6 Jul 2026 16:02:55 +0000 (+0200) Subject: cab: Clear lookup table in lzx_huffman_init X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4fa9fc1f37a4ecc654fac4621b89ac794efb2f7f;p=thirdparty%2Flibarchive.git cab: Clear lookup table in lzx_huffman_init This step is not actually needed, but will prevent static analysis warnings that values might exist which have never been initialized. "Invalid" values only exist outside of the addressable area, which can happen if maximum code bit length is smaller than table bit length. Signed-off-by: Tobias Stoeckmann --- diff --git a/libarchive/archive_read_support_format_cab.c b/libarchive/archive_read_support_format_cab.c index e5aeb58bf..0c5d48219 100644 --- a/libarchive/archive_read_support_format_cab.c +++ b/libarchive/archive_read_support_format_cab.c @@ -3210,20 +3210,23 @@ getdata: static int lzx_huffman_init(struct huffman *hf, size_t symbol_count, int tbl_bits) { + size_t tbl_size = (size_t)1 << tbl_bits; + if (hf->bitlen == NULL || hf->symbol_count != (int)symbol_count) { free(hf->bitlen); - hf->bitlen = calloc(symbol_count, sizeof(hf->bitlen[0])); + hf->bitlen = calloc(symbol_count, sizeof(hf->bitlen[0])); if (hf->bitlen == NULL) return (ARCHIVE_FATAL); hf->symbol_count = (int)symbol_count; } else - memset(hf->bitlen, 0, symbol_count * sizeof(hf->bitlen[0])); + memset(hf->bitlen, 0, symbol_count * sizeof(hf->bitlen[0])); if (hf->tbl == NULL) { - hf->tbl = malloc(((size_t)1 << tbl_bits) * sizeof(hf->tbl[0])); + hf->tbl = calloc(tbl_size, sizeof(hf->tbl[0])); if (hf->tbl == NULL) return (ARCHIVE_FATAL); hf->tbl_bits = tbl_bits; - } + } else + memset(hf->tbl, 0, tbl_size * sizeof(hf->bitlen[0])); return (ARCHIVE_OK); } @@ -3351,10 +3354,6 @@ lzx_make_huffman_table(struct huffman *hf) tbl = hf->tbl; bitlen = hf->bitlen; symbol_count = hf->symbol_count; - /* Initialize table to invalid values */ - for (i = 0; i < tbl_size; i++) { - tbl[i] = (uint16_t)hf->symbol_count; - } for (i = 0; i < symbol_count; i++) { uint16_t *p; int len, cnt;