Created
January 27, 2021 22:11
-
-
Save stevenjohnstone/44224d892a79e627850aefe8c51b759a to your computer and use it in GitHub Desktop.
Demonstration of issues with using gofuzz (no-hypen) with go-fuzz (has a hypen)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// +build gofuzz | |
// Package antifuzz shows how gofuzz transformation of inputs breaks coverage guidance. | |
// | |
// When running "go-fuzz -func FuzzGood", a crasher is found almost immediately. In contrast, | |
// when running "go-fuzz -func FuzzBad" no crasher is found and it likely won't for a long time. | |
package antifuzz | |
import fuzz "github.com/google/gofuzz" | |
func uut(data []byte) { | |
if len(data) < 5 { | |
return | |
} | |
if data[0] == 1 { | |
if data[1] == 2 { | |
if data[2] == 3 { | |
if data[3] == 4 { | |
if data[4] == 5 { | |
panic("found the bug") | |
} | |
} | |
} | |
} | |
} | |
} | |
// FuzzBad uses NewFromGoFuzz to build an input to uut. | |
func FuzzBad(data []byte) int { | |
var input []byte | |
fuzz.NewFromGoFuzz(data).Fuzz(&input) | |
uut(input) | |
return 0 | |
} | |
// FuzzGood simply passes in the data it receives from go-fuzz (note the hyphen). | |
func FuzzGood(data []byte) int { | |
uut(data) | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment