From 10aaa83ffec4414396b0c461ff0cf9918ecc4c40 Mon Sep 17 00:00:00 2001 From: Zoltan Szabadka Date: Mon, 28 Sep 2015 12:37:35 +0200 Subject: [PATCH] Fix a bug in ReadHuffmanCode(). --- dec/huffman.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dec/huffman.c b/dec/huffman.c index c68a404..2407670 100644 --- a/dec/huffman.c +++ b/dec/huffman.c @@ -88,6 +88,7 @@ void BrotliBuildCodeLengthsHuffmanTable(HuffmanCode* table, offset[bits] = symbol; bits++; }); + /* Symbols with code length 0 are placed after all other symbols. */ offset[0] = 17; /* sort symbols by length, by symbol order within each length */ @@ -101,8 +102,8 @@ void BrotliBuildCodeLengthsHuffmanTable(HuffmanCode* table, table_size = 1 << BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH; - /* special case code with only one value */ - if (offset[BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH] == 0) { + /* Special case: all symbols but one have 0 code length. */ + if (offset[0] == 0) { code.bits = 0; code.value = (uint16_t)sorted[0]; for (key = 0; key < table_size; ++key) {