em_inflate.c

Fast, small, in-memory inflate (zlib, deflate and gzip decompression)
git clone git://git.finwo.net/lib/em_inflate.c
Log | Files | Refs | README | LICENSE

commit 0ea8a0184fb32fd36f445b825504346faa773318
parent ce5cefef40ea6cc31355d84c2c33e3c935df548f
Author: Emmanuel Marty <emmanuel@fgl.com>
Date:   Sat, 10 Oct 2020 12:45:29 +0200

Better fix
Diffstat:
Mlib/em_inflate.c | 17++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/lib/em_inflate.c b/lib/em_inflate.c @@ -598,12 +598,19 @@ static size_t em_inflate_decompress_block(em_lsb_bitreader_t *pBitReader, int nD for (i = 0; i < NLITERALSYMS; i++) { unsigned int n = nLiteralsRevSymbolTable[i]; if (n >= NMATCHLENSYMSTART && n < NLITERALSYMS) { - int index = n - NMATCHLENSYMSTART; - if (index >= 0 && index < NMATCHLENSYMS) { + int index = n - NMATCHLENSYMSTART; + if (index >= 0 && index < NMATCHLENSYMS) { nLiteralsRevSymbolTable[i] = em_inflate_matchlen_code[index]; - } else { - return -1; - } + } + else { + if (n < NLITERALSYMS) { + /* Handle 287 and 288 codes, used for constructing a complete canonical tree, present in static huffman tables but not used */ + nLiteralsRevSymbolTable[i] = 0; + } + else { + return -1; + } + } } }