Skip to content

Commit

Permalink
inflate: Read more bits when decoding
Browse files Browse the repository at this point in the history
Fixes #231

When a block is not marked as the final block it should be possible to read 10 further bits ahead.

The smallest block seems to be a predefined block with a single EOB, which would be 10 bits + EOB from current block (current limit).

This should make it possible to fill more bits at the time when decoding.
  • Loading branch information
klauspost committed Feb 19, 2020
1 parent 2a5ec94 commit 4b5c701
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions flate/inflate.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,12 @@ func (f *decompressor) readHuffman() error {
// we never read any extra bytes after the end of the DEFLATE stream.
if f.h1.min < f.bits[endBlockMarker] {
f.h1.min = f.bits[endBlockMarker]
if !f.final {
// If not the final block, the smallest block possible is
// a predefined table with a single EOB marker.
// This will take up 3 + 7 bits.
f.h1.min += 10
}
}

return nil
Expand Down

0 comments on commit 4b5c701

Please sign in to comment.