Skip to content

Commit

Permalink
Fix infinite loop in GetBestLengths
Browse files Browse the repository at this point in the history
When compressing a file with a large run of repeated bytes, ECT could
skip full match finding without updating the match finder binary tree
correctly. This could lead to a rare infinite loop in match finding.
  • Loading branch information
fhanau committed Jan 7, 2024
1 parent 380a1df commit ec10745
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/LzFind.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,9 @@ void Bt3Zip_MatchFinder_Skip(CMatchFinder* p, UInt32 num)
}
}

//Same as above, but optimized for case where there is a ZOPFLI_MAX_MATCH len match at distance 1.
// Same as above, but optimized for case where there is a ZOPFLI_MAX_MATCH len match at distance 1.
// This implies that the match finder has processed at least one byte so far – otherwise there
// can't be available matches.
void Bt3Zip_MatchFinder_Skip2(CMatchFinder* p, UInt32 num)
{
const Byte *cur = p->buffer;
Expand Down
2 changes: 1 addition & 1 deletion src/zopfli/squeeze.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ static void GetBestLengths(const ZopfliOptions* options, const unsigned char* in
memset(p.hash, 0, LZFIND_HASH_SIZE * sizeof(unsigned));
p.cyclicBufferPos = 0;
p.pos = ZOPFLI_WINDOW_SIZE;
Bt3Zip_MatchFinder_Skip2(&p, 1);
Bt3Zip_MatchFinder_Skip(&p, 1);
}
else {
Bt3Zip_MatchFinder_Skip2(&p, match);
Expand Down

0 comments on commit ec10745

Please sign in to comment.