]> wimlib.net Git - wimlib/commitdiff
make_canonical_huffman_code(): Stricter validation of max_codeword_len
authorEric Biggers <ebiggers3@gmail.com>
Sat, 14 Jun 2014 04:33:08 +0000 (23:33 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 14 Jun 2014 04:34:35 +0000 (23:34 -0500)
max_codeword_len must be long enough to give a distinct codeword to each
symbol.  As we also check that num_syms >= 2, use this check instead of
max_codeword_len > 0.

src/compress_common.c

index 270b8cfe3b4ffd410a2cc02e0247e3327846f4a0..682a53c5f259e2416c995e6d88238f4070486949 100644 (file)
@@ -689,7 +689,7 @@ make_canonical_huffman_code(unsigned num_syms, unsigned max_codeword_len,
        /* Assumptions  */
        wimlib_assert2(num_syms >= 2);
        wimlib_assert2(num_syms <= (1 << NUM_SYMBOL_BITS));
-       wimlib_assert2(max_codeword_len > 0);
+       wimlib_assert2((1ULL << max_codeword_len) >= num_syms);
        wimlib_assert2(max_codeword_len <= 32);
 
        /* We begin by sorting the symbols primarily by frequency and