From 26488721a0cdb26c33f4e35f177c40fb81984346 Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Sat, 8 Dec 2018 15:21:22 +0100 Subject: [PATCH] codebook: reject invalid codes --- src/io/codebook.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/io/codebook.rs b/src/io/codebook.rs index 5bfd719..3d1e8d0 100644 --- a/src/io/codebook.rs +++ b/src/io/codebook.rs @@ -195,7 +195,12 @@ impl Codebook { let mut symidx: usize = 0; for i in 0..cb.len() { let bits = cb.bits(i); - if bits > 0 { nnz = nnz + 1; } + if bits > 0 { + nnz = nnz + 1; + if cb.code(i) >= (1 << bits) { + return Err(CodebookError::InvalidCodebook); + } + } maxbits = max(bits, maxbits); if bits > MAX_LUT_BITS { let code = cb.code(i); -- 2.39.5