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

[Rust] impl Follow for bool is unsound #5530

Closed
nagisa opened this issue Sep 24, 2019 · 4 comments · Fixed by #5554
Closed

[Rust] impl Follow for bool is unsound #5530

nagisa opened this issue Sep 24, 2019 · 4 comments · Fixed by #5554

Comments

@nagisa
Copy link

nagisa commented Sep 24, 2019

The implementation impl Follow for bool is defined here and ends up calling read_scalar_at::<bool>(...). read_scalar_at (defined here) is for all intents and purposes a transmute and therefore given a byte that is not exactly 0 or 1 will produce a value of bool that has an invalid underlying bit pattern. That is UB in Rust. Invoking it is as easy as

bool::follow(b"\x42", 0)

or something along the lines.

@aardappel
Copy link
Collaborator

Might be as simple as adding != 0 after the read_scalar_at call, and change its type to u8 or whatever?

@rw

@nagisa
Copy link
Author

nagisa commented Sep 25, 2019

Yes.

@rw
Copy link
Collaborator

rw commented Sep 28, 2019

@nagisa Nice catch! Want to try fixing that with a PR? You'd remove the line

impl_follow_for_endian_scalar!(bool);

and implement a new follow function for bool.

@nagisa
Copy link
Author

nagisa commented Sep 28, 2019

I would if SLA was not required – not really interested in dealing with the legalese.

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

Successfully merging a pull request may close this issue.

4 participants
@rw @nagisa @aardappel and others