Documentation ¶
Overview ¶
Package fuzzing enables easy fuzzing with (go-fuzz) https://github.com/dvyukov/go-fuzz.
The `Fuzz` object provides functions for generating consistent Go primitive values from a given fuzzed bytes slice. The generated values are promised to be consistent from identical slices. They are also correlated to the given fuzzed slice to enable fuzzing exploration.
For an example on how to use this library with go-fuzz, see ./example_fuzz.go In order to test the example, run in the project directory:
$ go get -u github.com/dvyukov/go-fuzz/go-fuzz github.com/dvyukov/go-fuzz/go-fuzz-build $ go-fuzz-build $ go-fuzz -testoutput
Example ¶
f := New([]byte{1, 2, 3}) i := f.Int() fmt.Println(i)
Output: 3851489450890114710
Index ¶
- type Fuzz
- func (f *Fuzz) Bool() bool
- func (f *Fuzz) Bytes(n int) []byte
- func (f *Fuzz) Int() int
- func (f *Fuzz) Int31() int32
- func (f *Fuzz) Int32() int32
- func (f *Fuzz) Int63() int64
- func (f *Fuzz) Int64() int64
- func (f *Fuzz) Read(b []byte) (int, error)
- func (f *Fuzz) ReadRune() (r rune, size int, err error)
- func (f *Fuzz) Rune() rune
- func (f *Fuzz) String(n int) string
- func (f *Fuzz) Uint() uint
- func (f *Fuzz) Uint32() uint32
- func (f *Fuzz) Uint64() uint64
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fuzz ¶
type Fuzz struct {
// contains filtered or unexported fields
}
Fuzz is a fuzzing helper object. It provides functions for generating consistent Go primitive values from a given fuzzed bytes slice. The generated values are promised to be consistent from a identical slices. They are also correlated to the given fuzzed slice to enable fuzzing exploration.
func New ¶
New returns a Fuzz (see Fuzz definition).
This function consumes that first 8 bytes and convert them to a uint64 for a random seed for pseudo random generator, the rest of the data is consumed as input to generate the fuzzed objects. When all the data is consumed, the created pseudo random generator is used to generate the fuzzed objects.
func (*Fuzz) Int31 ¶
Int31 consumes 4 bytes and return their conversion to int32 in the range [0, 1<<31).
func (*Fuzz) Int63 ¶
Int63 consumes 8 bytes and return their conversion to int64 in the range [0, 1<<63).
func (*Fuzz) Read ¶
Read reads from source. If the source was exhausted, it reads from the random fallback. The returned error should always be nil.