Skip to content

Commit ec10745

Browse files
committed
Fix infinite loop in GetBestLengths
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.
1 parent 380a1df commit ec10745

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/LzFind.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,9 @@ void Bt3Zip_MatchFinder_Skip(CMatchFinder* p, UInt32 num)
377377
}
378378
}
379379

380-
//Same as above, but optimized for case where there is a ZOPFLI_MAX_MATCH len match at distance 1.
380+
// Same as above, but optimized for case where there is a ZOPFLI_MAX_MATCH len match at distance 1.
381+
// This implies that the match finder has processed at least one byte so far – otherwise there
382+
// can't be available matches.
381383
void Bt3Zip_MatchFinder_Skip2(CMatchFinder* p, UInt32 num)
382384
{
383385
const Byte *cur = p->buffer;

src/zopfli/squeeze.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ static void GetBestLengths(const ZopfliOptions* options, const unsigned char* in
568568
memset(p.hash, 0, LZFIND_HASH_SIZE * sizeof(unsigned));
569569
p.cyclicBufferPos = 0;
570570
p.pos = ZOPFLI_WINDOW_SIZE;
571-
Bt3Zip_MatchFinder_Skip2(&p, 1);
571+
Bt3Zip_MatchFinder_Skip(&p, 1);
572572
}
573573
else {
574574
Bt3Zip_MatchFinder_Skip2(&p, match);

0 commit comments

Comments
 (0)