Skip to content
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

Implement Arbitrary for bitflags? #248

Closed
sunfishcode opened this issue Jul 23, 2021 · 3 comments · Fixed by #324
Closed

Implement Arbitrary for bitflags? #248

sunfishcode opened this issue Jul 23, 2021 · 3 comments · Fixed by #324

Comments

@sunfishcode
Copy link

Would it be worth it to have an optional implementation of Arbitrary (in the arbitrary crate) for bitflags types, to make it easier to use them in fuzzing?

I'm imagining something along the lines of this, added to the macro expansion when cfg(feature = "arbitrary") or so:

impl arbitrary::Arbitrary for $BitFlags {
    fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
         Self::from_bits(u.arbitrary()).ok_or_else(|| arbitrary::Error::IncorrectFormat)
    }
}
@KodrAus
Copy link
Member

KodrAus commented Aug 11, 2021

Can we think of any other implementation for Arbitrary that a consumer might want to add themselves? If not then this seems like a reasonable addition to me, since as I understand it, Arbitrary is meant to be a general API that different fuzzer implementations can lean on. Anything that makes fuzzing easier to get started with is worth doing! 😁

@sunfishcode
Copy link
Author

I've now submitted #260 implementing this.

@KodrAus
Copy link
Member

KodrAus commented Mar 13, 2023

We've recently published 2.0.0 that reworks the library internals to support new external trait implementations without breaking consumers. We should now be able to add an implementation for arbitrary following the support for serde as an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants