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

miri doesn't catch a violation of &mut [u8]'s validity invariants #1762

Closed
anp opened this issue Apr 7, 2021 · 4 comments
Closed

miri doesn't catch a violation of &mut [u8]'s validity invariants #1762

anp opened this issue Apr 7, 2021 · 4 comments

Comments

@anp
Copy link
Member

anp commented Apr 7, 2021

I think miri should fail on https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=a79f547a85d6d09e52756c2da3c121f4 because it produces an invalid &mut [u8] on line 11 (see context for reference interpretation).

Should it be an error to produce a &mut [u8] that references uninit bytes?

@anp
Copy link
Member Author

anp commented Apr 7, 2021

I missed this bit from the README: "In particular, Miri does currently not check that integers/floats are initialized or that references point to valid data."

@anp anp closed this as completed Apr 7, 2021
@RalfJung
Copy link
Member

RalfJung commented Apr 7, 2021

For the int/float part, #1340 tracks adding an option to check that.

But for references, I don't currently have plans to implement that -- it would be prohibitively expensive. Moreover I am anyway lobbying for relaxing that UB rule. ;)

@anp
Copy link
Member Author

anp commented Apr 7, 2021

Makes sense. I'm assuming it would still be prohibitive to treat slices differently than "thin" references.

I'd be interested to see a path for relaxing that rule, the ergonomics of single-write-only buffer usage is pretty rough. I have no idea what that'll look like, but you've got an eager audience :D.

@RalfJung
Copy link
Member

RalfJung commented Apr 8, 2021

I'd be interested to see a path for relaxing that rule,

The discussion is at rust-lang/unsafe-code-guidelines#77. ;)
To summarize, I think we should change the description of invalid references from

A reference or Box that is dangling, unaligned, or points to an invalid value.

to

A reference or Box that is dangling, unaligned, or points to an uninhabited type (i.e., a type with no valid value).

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

No branches or pull requests

2 participants