-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
[dev.fuzz] testing: crash due to incompatible type #45593
Comments
Ah thanks for testing and reporting this! There's probably something better we can do here, like you said. So I'll think about that more. At the very least we can improve the error messaging to say something more direct. It would be great to be able to use generics at some point soon. It would likely help for cases like this. If we can't, then at the very least we can add |
Although, I'm not sure if it's going to be possible with the currently accepted generics proposal since it doesn't support variadic type parameters. A |
I put this in backlog for now, but is it a release blocker? |
One tricky thing to consider is that we have to decide what our source of truth is if the arguments differ. For example, consider these two fuzz targets:
b)
Should we pick int64 values to fuzz and write to the corpus, since that can hold the most bytes, and is thus the most likely to be able to assign to? Or should we assume that the arguments in the Do you have an opinion on this? |
I believe |
Change https://golang.org/cl/325702 mentions this issue: |
The types provided in f.Fuzz will be viewed as the canonical types for fuzzing. If the type is different for a seed corpus entry, then the testing package will attempt to convert it. If it can't convert it, f.Fuzz will fail. Currently, this allows converting types that may result in precision loss or a semantically different value. For example, an int(-1) can be converted to uint even though the value could be math.MaxUint64. There is a TODO to consider improving this in the future. Updates #45593 Change-Id: I2e752119662f46b68445d42b1ffa46dd30e9faea Reviewed-on: https://go-review.googlesource.com/c/go/+/325702 Trust: Katie Hockman <katie@golang.org> Run-TryBot: Katie Hockman <katie@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org>
I've been thinking about this a bit more, and at least for the first major release of fuzzing, I don't think we should be attempting to convert inputs of different types. I'd like to revert the part of my change that does the conversion. I agree that the UX could be better even without doing this though: at the very least with a better error message (which I'm happy to do). I'm concerned that if this ends up causing problems later down the line, then the backwards compatibility promises are going to make us keep it around even when we don't want to. We can always make it less restrictive later, but we can't do the opposite. @dsnet do you feel strongly about this either way? @golang/fuzzing |
I don't feel strongly, but I support a revert. I prefer stricter checks over automatic conversions that have surprising edge cases. It seems more aligned with the Go philosophy that requires manually casting integers of different widths rather than automatically casting them. |
Change https://golang.org/cl/350251 mentions this issue: |
…re possible" This reverts commit 413c125. Reason for revert: Giving this more thought, we've decided that converting types under the hood may cause unexpected behavior to users. This is a feature that can always be added after more consideration has been done, but is not something that can be removed due to the backwards compatibility promise. Updates #45593 Change-Id: I79bab24979d7e4c294e6cb6455d4c7729d6a0efb Reviewed-on: https://go-review.googlesource.com/c/go/+/350251 Trust: Katie Hockman <katie@golang.org> Trust: Joe Tsai <joetsai@digital-static.net> Run-TryBot: Katie Hockman <katie@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com> Reviewed-by: Joe Tsai <joetsai@digital-static.net>
I've gone ahead and reverted the change, and will close the issue now. If there are still changes we should make as far as printing a better error message, feel free to re-open or just file a new issue with those details. |
I wonder if it would make sense to restore the implicit conversions, but only from the default types of constants ( That might give some of the ergonomic benefits of conversion for |
(Either way, I think it's totally fine to keep the check strict for Go 1.18!) |
Using 529e5d0.
Consider this snippet:
Currently, this crashes with:
The cause of the crash is because
testing.F.Add
is called with anint
, while the Fuzz function itself is expecting anint64
.Either, the testing framework should:
Also, with generics on the horizon, is there an API design that would guarantee type safety between
testing.F.Add
andtesting.F.Fuzz
? It's probably better to statically prevent type errors like than to have it occur at runtime.\cc @katiehockman @jayconrod
The text was updated successfully, but these errors were encountered: