-
Notifications
You must be signed in to change notification settings - Fork 355
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
Running Miri on Playground does not error when printing non-UTF-8 output #1309
Comments
Hm, that is curious. First of all, I don't think this code has UB, at least not UB that Miri currently is designed to find. The only possible UB here is "creating a non-UTF8
Moreover, the UTF-8 condition is not something the compiler actually exploits currently. Also see rust-lang/unsafe-code-guidelines#78; the general consensus was that we should just remove the UTF-8 clause from the language spec and make it purely a case of library UB. (In other words, UTF-8 would be a safety invariant, but not a validity invariant.) Now, to the error you are seeing when pressing "Run" above. I think that error is actually coming from the playground:
@shepmaster, could you confirm? @elichai did you try running this example locally with |
I did not know that "playground effects" were a thing, how/what are these? |
I did not know either. But the output looked different from when the program itself prints something, where we also get
so I concluded it wasn't the program printing this, but playground. Which also made more sense because the error message did not at all sound like UB, and if this was a regular assertion inside the program then Miri would also evaluate it. |
Ah yes, looks like it's that (though curiously that bug seems to not affect Miri output). Closing as duplicate of rust-lang/rust-playground#386 then. |
There's still some difference in how Miri treats this code that seems suspicious:
Shouldn't Miri output the same as |
Hm, strange. Looks like "8b" turned into "ef bf bd", whatever that means. The Miri code that does the printing is here: miri/src/shims/foreign_items/posix.rs Lines 68 to 81 in d935f62
This should not do anything "weird" wrt. UTF-8. |
@shepmaster I cannot reproduce this locally, both are the same here.
What are the exact commands you used to create your two files? |
I did do some small editing in vim to remove Cargo noise from the generated files, but AFAICT nothing changed. I am on macOS 10.15.3 (19D76). |
Changing to stdout has the same behavior but easier to see: fn main() {
let s = unsafe { std::str::from_utf8_unchecked(&[139, 50]) };
println!("{}", s);
}
|
Hm indeed, I can reproduce this even when using I will open a new issue for that though, seems unrelated to the playground problem this here was originally about. Thanks for pointing this out! I suspect it is a cargo problem, but it is still good to know. |
That bit nerdsniped me into taking a stab at (I am aware that doesn't change much, and miri still checks |
So it seems that somehow miri bypasses the the check for UTF8 validity when printing a str
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=393c2e1fe450d4a03e7a1d293d54d04e
It's a bit too late here for me to debug where it's happening in libstd right now.
The text was updated successfully, but these errors were encountered: