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

impl Arbitrary for Uuid to enable easy integration of cargo-fuzz #514

Closed
blasrodri opened this issue Mar 1, 2021 · 3 comments · Fixed by #550
Closed

impl Arbitrary for Uuid to enable easy integration of cargo-fuzz #514

blasrodri opened this issue Mar 1, 2021 · 3 comments · Fixed by #550

Comments

@blasrodri
Copy link

blasrodri commented Mar 1, 2021

Is your feature request related to a problem? Please describe.
It's common to have obejcts that use Uuid. And whenever someone wants to use rust-fuzz, all the components
of the object need to implement/derive the Arbitrary trait

Describe the solution you'd like
Having an implementation for Arbitrary for Uuid

Something like this would be a starting point:

impl Arbitrary<'_> for Uuid {
    fn arbitrary(u: &mut Unstructured<'_>) -> ArbitraryResult<Self> {
        let b = u.bytes(16)?;
        Ok(Uuid::from_bytes(b.try_into().unwrap()))
    }
}

However, I assume it will panic most of the time. So, I'm not sure what's the best way to go about it.

@KodrAus
Copy link
Member

KodrAus commented Aug 12, 2021

I can imagine the most useful use of fuzzing with uuids would be to also mess with the versions so you don't just always receive an already random v4 uuid. If we just want to unblock #[derive(Arbitrary)] on types that contain Uuid fields though, then we could reasonably just use uuid::Builder to accept 16 random bytes and then set the version to v4 so it becomes infallible.

I'd be ok with adding an optional arbitrary feature to uuid, since the crate is 1.0 and am on-board with making life easier for everyone getting started with fuzzing.

@greyblake
Copy link

Uh, I miss something like this. Alternatively an implementation could go to Arbitrary crate.

@KodrAus
Copy link
Member

KodrAus commented Oct 31, 2021

@greyblake At this stage uuid is probably the better place for it. We're working on stabilizing the library now, but until then I wouldn't expect arbitrary to want to add a public implementation for an unstable library 🙂

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

Successfully merging a pull request may close this issue.

3 participants