-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Soundness: clap_lex makes incorrect assumption about OsStr #5280
Comments
While I generally feel I'm not creative enough to play these games, when I analyzed this, I could not find a way that the language or standard library can change that would violate this assumption because of the roundtripping involved with the conversions: "ref to DST" ( I guess if the language allowed refs to DSTs to choose their representation ( As you said, |
Yes, that it's still not a documented invariant; I'm in general not comfortable relying on those in unsafe code and usually note them when performing unsafe review. I mostly filed this issue so I have something to point to in the published unsafe audit, it's not a huge deal and this will be a non-problem in the future anyway. DSTs changing their representation is indeed a real worry. In general it's not a huge one: so much code relies on DST repr that it's unlikely to change without major warning, but that still does make it important to track. Fortunately in this case it will be fixed before any such change can come down the pipeline. |
While I am fixing this (#4344), I'm wanting to understand this further as I find other needs for transmuting DSTs into each other ( |
The metadata order could swap. And the provenance could be weird. |
So two DSTs in the same rustc version could have metadata in different order? That seems odd. |
Rust has So yes, that is a potential reality. |
clap/clap_lex/src/ext.rs
Lines 248 to 256 in 48d28aa
It's not true that
OsStr
is stably a transparent wrapper around[u8]
, this code is technically unsound. It's fine as long as the Rust stdlib avoids making this change.Fortunately the soon-to-be-stabilized
as_os_str_bytes()
will fix this. Opening this issue to track it.The text was updated successfully, but these errors were encountered: