Skip to content

Commit 2bcf1c0

Browse files
internal/fuzz: don't add duplicate corpus entries
If a identical input is already present in the corpus, don't re-add it. This may happen when the same input produces a different coverage map, causing the coordinator to think it has found a new input. This fixes a race between reading/writing cached inputs. Fixes #48721 Change-Id: I4807602f433c2b99396d25ceaa58b827796b3555 Reviewed-on: https://go-review.googlesource.com/c/go/+/359755 Trust: Roland Shoemaker <[email protected]> Trust: Katie Hockman <[email protected]> Run-TryBot: Roland Shoemaker <[email protected]> Run-TryBot: Katie Hockman <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Katie Hockman <[email protected]>
1 parent 80bedb8 commit 2bcf1c0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/internal/fuzz/fuzz.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,23 @@ func CoordinateFuzzing(ctx context.Context, opts CoordinateFuzzingOpts) (err err
316316
// Update the coordinator's coverage mask and save the value.
317317
inputSize := len(result.entry.Data)
318318
if opts.CacheDir != "" {
319+
// It is possible that the input that was discovered is already
320+
// present in the corpus, but the worker produced a coverage map
321+
// that still expanded our total coverage (this may happen due to
322+
// flakiness in the coverage counters). In order to prevent adding
323+
// duplicate entries to the corpus (and re-writing the file on
324+
// disk), skip it if the on disk file already exists.
325+
// TOOD(roland): this check is limited in that it will only be
326+
// applied if we are using the CacheDir. Another option would be
327+
// to iterate through the corpus and check if it is already present,
328+
// which would catch cases where we are not caching entries.
329+
// A slightly faster approach would be to keep some kind of map of
330+
// entry hashes, which would allow us to avoid iterating through
331+
// all entries.
332+
_, err = os.Stat(result.entry.Path)
333+
if err == nil {
334+
continue
335+
}
319336
err := writeToCorpus(&result.entry, opts.CacheDir)
320337
if err != nil {
321338
stop(err)

0 commit comments

Comments
 (0)