Benzinga / lz4js

Lz4 for the browser.
89 stars 21 forks source link

Respect LZ4 end of block conditions #13

Open rlespinet opened 1 year ago

rlespinet commented 1 year ago

Lz4js compress can produce outputs that are not conformant with LZ4 official format. This is due to end of block conditions spcified in https://github.com/lz4/lz4/blob/dev/doc/lz4_Block_format.md and more specifically the following:

"The last match must start at least 12 bytes before the end of block"

For example, prior to this change, when compressing the following string (ASCII encoded) with lz4js

"AbcdefghijklmnopAbcdefghijk"

a match starting only 11 bytes before the end of the output buffer (corresponding to "Abcdefghijk") would have been created, leading to an invalid output bitstream. Official LZ4 decoder would fail to decompress this bitstream. This commit prevents matches occuring (strictly) less than 12 bytes before the end of the block.

Fixes #12