Skip to content
Snippets Groups Projects
Commit 15ebaddc authored by Scott Vokes's avatar Scott Vokes
Browse files

Change MIN_LOOKAHEAD_BITS from 2 to 3 to prevent ambiguity.

As reported by @unixdj, there is a case where a few bytes can be
dropped from the end of the bytestream when used with a window_sz2
of 4 and lookahead_sz2 of 2 (-w 4 -l 2):

    $ echo -n aaaa | ./heatshrink -e -w4 -l2 | ./heatshrink -d -w4 -l2
    a   # should be "aaaa"

While st_check_for_input can treat 7 bits as sufficient input when
-w is 4 and -l is 2, that creates a corresponding issue where 1
spillover bit from the previous byte leads to filler of 0b000 0000,
which is interpreted as a marker to repeat (0b0) from 1 byte back
(0b0000) for 1 byte (0b00), leading to a duplication of the last
byte of input. Using a w,l pair where w+l < 7 leads to trailing
bits that are ambiguous, so raise the minimum lookahead bits to 3.

This problem does not occur with -w 4 -l 3, or any other valid config.
parent 25c18261
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment