From a94409660dbf05c1cdc2013aa2c7aa2489fe5c1c Mon Sep 17 00:00:00 2001 From: Roland Shoemaker Date: Thu, 18 Nov 2021 13:30:55 -0800 Subject: [PATCH] internal/fuzz: compute correct number of mutations When reconstructing inputs, we miscalculated the number of mutations that needed to be applied. If the count%chainedMutation == 0 we would apply 0 mutations, when we should actually be applying chainedMutation mutations, due to how count is incremented. Fixes #49047 Change-Id: I76773bff0afd6dfd40deafc317be095da995ecc5 Reviewed-on: https://go-review.googlesource.com/c/go/+/365294 Trust: Roland Shoemaker Trust: Katie Hockman Run-TryBot: Roland Shoemaker Run-TryBot: Katie Hockman Reviewed-by: Bryan C. Mills Reviewed-by: Katie Hockman TryBot-Result: Go Bot --- src/cmd/go/testdata/script/test_fuzz_mutator_repeat.txt | 2 -- src/internal/fuzz/worker.go | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cmd/go/testdata/script/test_fuzz_mutator_repeat.txt b/src/cmd/go/testdata/script/test_fuzz_mutator_repeat.txt index 5b1e26be24..3764dcb915 100644 --- a/src/cmd/go/testdata/script/test_fuzz_mutator_repeat.txt +++ b/src/cmd/go/testdata/script/test_fuzz_mutator_repeat.txt @@ -1,5 +1,3 @@ -skip # https://golang.org/issue/49047 - # TODO(jayconrod): support shared memory on more platforms. [!darwin] [!linux] [!windows] skip diff --git a/src/internal/fuzz/worker.go b/src/internal/fuzz/worker.go index e7d824bea1..5be49d28f9 100644 --- a/src/internal/fuzz/worker.go +++ b/src/internal/fuzz/worker.go @@ -1111,7 +1111,8 @@ func (wc *workerClient) fuzz(ctx context.Context, entryIn CorpusEntry, args fuzz wc.m.r.restore(mem.header().randState, mem.header().randInc) if !args.Warmup { // Only mutate the valuesOut if fuzzing actually occurred. - for i := int64(0); i < resp.Count%chainedMutations; i++ { + numMutations := ((resp.Count - 1) % chainedMutations) + 1 + for i := int64(0); i < numMutations; i++ { wc.m.mutate(valuesOut, cap(mem.valueRef())) } } -- 2.50.0