Skip to content

Respect LZ4 end of block conditions - #13

Open
rlespinet wants to merge 1 commit into
Benzinga:masterfrom
rlespinet:master
Open

Respect LZ4 end of block conditions#13
rlespinet wants to merge 1 commit into
Benzinga:masterfrom
rlespinet:master

Conversation

@rlespinet

@rlespinet rlespinet commented Feb 16, 2023

Copy link
Copy Markdown

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

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.
coyotte508 added a commit to huggingface/huggingface.js that referenced this pull request Mar 13, 2025
The published version of lz4js is outdated, this code also includes
a fix from Benzinga/lz4js#13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compression does not respect LZ4 official End of block conditions

1 participant