google / gofuzz

Fuzz testing for go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is / should gofuzz safe for concurrent use?

alarbada opened this issue · comments

I've had several data races with stack traces like this:

  math/rand.(*rngSource).Uint64()
      /usr/local/go/src/math/rand/rng.go:249 +0x190
  math/rand.(*rngSource).Int63()
      /usr/local/go/src/math/rand/rng.go:234 +0x1f1
  math/rand.(*Rand).Int63()
      /usr/local/go/src/math/rand/rand.go:84 +0x70
  math/rand.(*Rand).Int31()
      /usr/local/go/src/math/rand/rand.go:98 +0x81
  math/rand.(*Rand).Int31n()
      /usr/local/go/src/math/rand/rand.go:133 +0x45
  math/rand.(*Rand).Intn()
      /usr/local/go/src/math/rand/rand.go:171 +0x48
  github.com/google/gofuzz.UnicodeRanges.randString()
      /home/guillem/golang/pkg/mod/github.com/google/gofuzz@v1.2.0/fuzz.go:586 +0x48
  github.com/google/gofuzz.randString()
      /home/guillem/golang/pkg/mod/github.com/google/gofuzz@v1.2.0/fuzz.go:598 +0x6f
  github.com/google/gofuzz.glob..func6()
      /home/guillem/golang/pkg/mod/github.com/google/gofuzz@v1.2.0/fuzz.go:491 +0x70
  github.com/google/gofuzz.(*fuzzerContext).doFuzz()
      /home/guillem/golang/pkg/mod/github.com/google/gofuzz@v1.2.0/fuzz.go:271 +0x76e
  github.com/google/gofuzz.(*fuzzerContext).doFuzz()
      /home/guillem/golang/pkg/mod/github.com/google/gofuzz@v1.2.0/fuzz.go:302 +0xa29
  github.com/google/gofuzz.(*fuzzerContext).doFuzz()
      /home/guillem/golang/pkg/mod/github.com/google/gofuzz@v1.2.0/fuzz.go:327 +0x946
  github.com/google/gofuzz.(*Fuzzer).fuzzWithContext()
      /home/guillem/golang/pkg/mod/github.com/google/gofuzz@v1.2.0/fuzz.go:239 +0x224
  github.com/google/gofuzz.(*Fuzzer).Fuzz()
      /home/guillem/golang/pkg/mod/github.com/google/gofuzz@v1.2.0/fuzz.go:213 +0x18e

so, I guess it is not. Should it be?

The expectation is that you'll just construct a fuzzer per goroutine (use different seeds!), that will give better performance than internally locking the rng.

Cool, thanks