diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2017-10-16 01:02:54 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2017-10-16 01:03:45 -0700 |
commit | 79f88bd1e54d6042fbe50c212f836920fa208e56 (patch) | |
tree | e4e25411e571e770675dfb86f7646589eaa47d60 /unpack.c | |
parent | 5d0ae40d0767f0783e796813f6099ae0168f6dd4 (diff) | |
download | gzip-79f88bd1e54d6042fbe50c212f836920fa208e56.tar.gz |
gzip: fix bug in unpack EOB check
Problem reported by Vidar Holen (Bug#28861).
* NEWS: Mention fix.
* tests/unpack-valid: New test.
* tests/Makefile.am (TESTS): Add it.
* unpack.c (build_tree): Report an error if Huffman tree has
too few leaves.
* unpack.c (unpack): Fix check for EOB.
Remove now-unnecessary check for code out of range.
Diffstat (limited to 'unpack.c')
-rw-r--r-- | unpack.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -186,6 +186,9 @@ local void build_tree() /* Restore nodes to be parents+leaves: */ nodes += leaves[len]; } + if ((nodes >> 1) != 1) + gzip_error ("too few leaves in Huffman tree"); + /* Construct the prefix table, from shortest leaves to longest ones. * The shortest code is all ones, so we start at the end of the table. */ @@ -250,10 +253,8 @@ int unpack(in, out) } } /* At this point, peek is the next complete code, of len bits */ - if (peek == eob) + if (peek == eob && len == max_len) break; /* End of file. */ - if (eob < peek) - gzip_error ("invalid compressed data--code out of range"); put_ubyte(literal[peek+lit_base[len]]); Tracev((stderr,"%02d %04x %c\n", len, peek, literal[peek+lit_base[len]])); |