-
Notifications
You must be signed in to change notification settings - Fork 18k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
testing: fuzzed function can corrupt internal state of fuzzer #48606
Comments
cc @golang/fuzzing |
Allocating a new |
Change https://golang.org/cl/353429 mentions this issue: |
@jayconrod brought up a good point during review of https://golang.org/cl/353429 that makes a case for why we shouldn't be allowing the fuzzed functions to alter the underlying data that is provided by the fuzzing engine. Namely, he brought up that this will be next to impossible when structs are supported in the future. He noted that we would need to allocate a new struct every time the fuzz function is called, which isn't tenable for performance (fuzzing has to be fast to be effective). One potential option that I brought up is that we support this for []byte only, but not for structs, but special-casing like this makes the code more difficult to maintain and makes things like documentation less straightforward. This may be something that can be supported in the future after more thought has gone into it, but for now, it sounds like the best course of action is to make it a requirement that the fuzz target is not allowed to alter the underlying data during fuzzing. It's easier to loosen the restriction in future releases then to design ourselves into a corner today. If folks have good examples of cases where functions like this should be fuzzable, please comment here. |
As far as how to make this a requirement, I would say that documenting it in |
Change https://golang.org/cl/353977 mentions this issue: |
@katiehockman I wonder how we can enforce that only functions which don't modify their arguments can be fuzzed? How do I know I haven't done that by mistake? #47587 is an example in the fuzzing code. This bug itself could be considered to be another. I also have doubts that I'd be able to vouch for all the dependencies of a function under test. I've written a few bugs where I meant to copy data but didn't. It seems to be common enough to end up in coding guidelines: https://github.com/uber-go/guide/blob/master/style.md#copy-slices-and-maps-at-boundaries. This is all fine though if there are tools to discover that arguments have been changed. I'd be really happy with auxiliary functions in the testing package which would give lightweight checksums of arguments which are friendly to the performance requirements of the fuzzer. In vague pseudo-code c := testing.Checksum(arg)
func(arg)
if testing.Checksum(arg) != c {
panic("argument modified")
} I'd be okay with writing my own functions for that but I'm really keen to advocate fuzzing and making it as easy as possible would help there. |
@stevenjohnstone I think the way you described would be a workable approach for this. @jayconrod had a similar suggestion: "We could potentially enforce this by hashing the data before and after each call and stopping if the hashes don't match. Hashing should be at least marginally faster than allocating and garbage collecting." I agree that we should do something like this if we have the time to do so. At the very least, we can make this a strong nice-to-have. It's a bit unclear how much effort would be involved in implementing this, so I didn't want to make it a release-blocker for 1.18 yet, especially given the fact that there are still several other bug fixes and quality-of-life improvements we should make before the cut. I'll take a closer look though and see if it's reasonable to implement for 1.18. Thanks for the feedback 👍 |
Updates #48606 Change-Id: I6d555fdefccd842fb65ec8d630b4808bcb54a825 Reviewed-on: https://go-review.googlesource.com/c/go/+/353977 Trust: Katie Hockman <katie@golang.org> Run-TryBot: Katie Hockman <katie@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
I actually think this should be pretty straightforward. I'm working on this now, so hopefully can send a patch shortly. |
Looking into this more, we should fix #48804 before we fix this, since we need that fixed for the error messages to be handled and reported correctly. But once that's done, I think this should be pretty straightforward. My biggest concern with the hash approach is that we can't hash the |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Ran the following:
The "crasher" in the
testdata
directory does not cause a crash.Running with minimization disabled also reveals an issue:
What did you expect to see?
Crashers stored in
testdata
should trigger crashes.What did you see instead?
Corpus entry was not a crasher.
The text was updated successfully, but these errors were encountered: