diff options
| author | Roland Shoemaker <roland@golang.org> | 2022-03-10 12:16:33 -0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-03-10 22:50:18 +0000 |
| commit | bd71dee2b4c0a44f9c32e9eb23d990b54ce06bae (patch) | |
| tree | 898203a0c9305174cf18baf57e90a9d2fd8592c5 /src/internal/fuzz | |
| parent | 914195c132cbec651aa43c409e8aac2614b53b38 (diff) | |
| download | go-bd71dee2b4c0a44f9c32e9eb23d990b54ce06bae.tar.xz | |
internal/fuzz: don't use dirty coverage maps during minimization
When minimizing a value, if the value cannot be minimized (i.e. it is
the final value is the same value as was sent for minimization) return
the initial coverage map, rather than the coverageSnapshot, which is
actually the coverage map for the final minimization step and may not
accurately reflect whether the input actually expands the coverage set
or not.
Updates #48326
Change-Id: I01f0eebe5841e808b6799647d2e5fe3aa45cd2e0
Reviewed-on: https://go-review.googlesource.com/c/go/+/391614
Reviewed-by: Bryan Mills <bcmills@google.com>
Trust: Roland Shoemaker <roland@golang.org>
Run-TryBot: Roland Shoemaker <roland@golang.org>
Auto-Submit: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/internal/fuzz')
| -rw-r--r-- | src/internal/fuzz/worker.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/internal/fuzz/worker.go b/src/internal/fuzz/worker.go index e984ba73b2..83d937ee6d 100644 --- a/src/internal/fuzz/worker.go +++ b/src/internal/fuzz/worker.go @@ -800,6 +800,7 @@ func (ws *workerServer) minimize(ctx context.Context, args minimizeArgs) (resp m if err != nil { panic(err) } + inpHash := sha256.Sum256(mem.valueCopy()) if args.Timeout != 0 { var cancel func() ctx, cancel = context.WithTimeout(ctx, args.Timeout) @@ -811,12 +812,22 @@ func (ws *workerServer) minimize(ctx context.Context, args minimizeArgs) (resp m success, err := ws.minimizeInput(ctx, vals, mem, args) if success { writeToMem(vals, mem) + outHash := sha256.Sum256(mem.valueCopy()) mem.header().rawInMem = false resp.WroteToMem = true if err != nil { resp.Err = err.Error() } else { - resp.CoverageData = coverageSnapshot + // If the values didn't change during minimization then coverageSnapshot is likely + // a dirty snapshot which represents the very last step of minimization, not the + // coverage for the initial input. In that case just return the coverage we were + // given initially, since it more accurately represents the coverage map for the + // input we are returning. + if outHash != inpHash { + resp.CoverageData = coverageSnapshot + } else { + resp.CoverageData = args.KeepCoverage + } } } return resp |
