From aac5c5d0df942ad12e4f026eed4603a2ffdebe3c Mon Sep 17 00:00:00 2001 From: James Zern Date: Mon, 14 Aug 2023 17:59:42 -0700 Subject: [PATCH] ReadHuffmanCode: rm redundant num code lengths check 4 bits are read ([0, 15]) with 4 added to the result. The check that the result is not > NUM_CODE_LENGTH_CODES (19) is redundant. This makes the check an assert for documentation purposes. webp-lossless-bitstream-spec.txt is updated accordingly. Bug: webp:611 Change-Id: Ie461017dc9de3da4cfe6856543d3dcf58f53a180 --- doc/webp-lossless-bitstream-spec.txt | 2 -- src/dec/vp8l_dec.c | 5 ++--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/doc/webp-lossless-bitstream-spec.txt b/doc/webp-lossless-bitstream-spec.txt index 26eb0d6a..1f934c4b 100644 --- a/doc/webp-lossless-bitstream-spec.txt +++ b/doc/webp-lossless-bitstream-spec.txt @@ -904,8 +904,6 @@ First, `num_code_lengths` specifies the number of code lengths. int num_code_lengths = 4 + ReadBits(4); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -If `num_code_lengths` is greater than 19, the bitstream is invalid. - The code lengths are themselves encoded using prefix codes; lower-level code lengths, `code_length_code_lengths`, first have to be read. The rest of those `code_length_code_lengths` (according to the order in `kCodeLengthCodeOrder`) diff --git a/src/dec/vp8l_dec.c b/src/dec/vp8l_dec.c index 8c1437d7..45012162 100644 --- a/src/dec/vp8l_dec.c +++ b/src/dec/vp8l_dec.c @@ -12,6 +12,7 @@ // Authors: Vikas Arora (vikaas.arora@gmail.com) // Jyrki Alakuijala (jyrki@google.com) +#include #include #include "src/dec/alphai_dec.h" @@ -339,9 +340,7 @@ static int ReadHuffmanCode(int alphabet_size, VP8LDecoder* const dec, int i; int code_length_code_lengths[NUM_CODE_LENGTH_CODES] = { 0 }; const int num_codes = VP8LReadBits(br, 4) + 4; - if (num_codes > NUM_CODE_LENGTH_CODES) { - return VP8LSetError(dec, VP8_STATUS_BITSTREAM_ERROR); - } + assert(num_codes <= NUM_CODE_LENGTH_CODES); for (i = 0; i < num_codes; ++i) { code_length_code_lengths[kCodeLengthCodeOrder[i]] = VP8LReadBits(br, 3);