diff --git a/s2/dict_test.go b/s2/dict_test.go index 1b478e4165..9ac9f70c7c 100644 --- a/s2/dict_test.go +++ b/s2/dict_test.go @@ -402,13 +402,14 @@ func TestDictSize(t *testing.T) { } }) } - fmt.Printf("%d files, %d -> %d (%.2f%%) - %.02f bytes saved/file\n", totalCount, totalIn, totalOut, float64(totalOut*100)/float64(totalIn), float64(totalIn-totalOut)/float64(totalCount)) + t.Logf("%d files, %d -> %d (%.2f%%) - %.02f bytes saved/file\n", totalCount, totalIn, totalOut, float64(totalOut*100)/float64(totalIn), float64(totalIn-totalOut)/float64(totalCount)) } func FuzzDictBlocks(f *testing.F) { fuzz.AddFromZip(f, "testdata/enc_regressions.zip", fuzz.TypeRaw, false) fuzz.AddFromZip(f, "testdata/fuzz/block-corpus-raw.zip", fuzz.TypeRaw, testing.Short()) fuzz.AddFromZip(f, "testdata/fuzz/block-corpus-enc.zip", fuzz.TypeGoFuzz, testing.Short()) + fuzz.AddFromZip(f, "testdata/fuzz/dict-corpus-oss.zip", fuzz.TypeOSSFuzz, testing.Short()) // Fuzzing tweaks: const ( diff --git a/s2/encode_best.go b/s2/encode_best.go index 1d13e869a1..47bac74234 100644 --- a/s2/encode_best.go +++ b/s2/encode_best.go @@ -157,6 +157,9 @@ func encodeBlockBest(dst, src []byte, dict *Dict) (d int) { return m } matchDict := func(candidate, s int, first uint32, rep bool) match { + if s >= MaxDictSrcOffset { + return match{offset: candidate, s: s} + } // Calculate offset as if in continuous array with s offset := -len(dict.dict) + candidate if best.length != 0 && best.s-best.offset == s-offset && !rep { diff --git a/s2/testdata/fuzz/dict-corpus-oss.zip b/s2/testdata/fuzz/dict-corpus-oss.zip new file mode 100644 index 0000000000..99a06c13f2 Binary files /dev/null and b/s2/testdata/fuzz/dict-corpus-oss.zip differ