]> wimlib.net Git - wimlib/blobdiff - src/compress_common.c
make_canonical_huffman_code(): Stricter validation of max_codeword_len
[wimlib] / src / compress_common.c
index e8ed00d3c3096e810b46d67ef4617d5196618058..682a53c5f259e2416c995e6d88238f4070486949 100644 (file)
@@ -33,7 +33,6 @@
 #include "wimlib/compress_common.h"
 #include "wimlib/util.h"
 
-#include <stdlib.h>
 #include <string.h>
 
 /* Writes @num_bits bits, given by the @num_bits least significant bits of
@@ -553,8 +552,8 @@ gen_codewords(u32 A[restrict], u8 lens[restrict],
  * approximately (with the algorithm used here) the minimum weighted path
  * length from the root, given this constraint.
  *
- * A canonical Huffman code satisfies the properties that a codeword
- * never lexicographically precedes a shorter codeword, and the
+ * A canonical Huffman code satisfies the properties that a longer
+ * codeword never lexicographically precedes a shorter codeword, and the
  * lexicographic ordering of codewords of the same length is the same as
  * the lexicographic ordering of the corresponding symbols.  A canonical
  * Huffman code, or more generally a canonical prefix code, can be
@@ -690,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