-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
PathBuf incorrectly transmutes OsString to Vec<u8> #124409
Comments
rustbot
added
the
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
label
Apr 26, 2024
This was referenced Apr 26, 2024
bors
added a commit
to rust-lang/miri
that referenced
this issue
Apr 26, 2024
add smoke tests for basic PathBuf interactions I wrote these while debugging [this](https://github.com/rust-lang/miri-test-libstd/actions/runs/8849912635/job/24302962983); it turns out the issue is [more complicated](rust-lang/rust#124409) but these tests still seemed worth keeping.
This was referenced Apr 26, 2024
Noratrieb
added
C-bug
Category: This is a bug.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
and removed
needs-triage
This issue may need triage. Remove it if it has been sufficiently triaged.
labels
Apr 26, 2024
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Apr 26, 2024
…strieb PathBuf: replace transmuting by accessor functions The existing `repr(transparent)` was anyway insufficient as `OsString` was not `repr(transparent)`. And furthermore, on Windows it was blatantly wrong as `OsString` wraps `Wtf8Buf` which is a `repr(Rust)` type with 2 fields: https://github.com/rust-lang/rust/blob/51a7396ad3d78d9326ee1537b9ff29ab3919556f/library/std/src/sys_common/wtf8.rs#L131-L146 So let's just be honest about what happens and add accessor methods that make this abstraction-breaking act of PathBuf visible on the APIs that it pierces through. Fixes rust-lang#124409
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Apr 27, 2024
Rollup merge of rust-lang#124410 - RalfJung:path-buf-transmute, r=Nilstrieb PathBuf: replace transmuting by accessor functions The existing `repr(transparent)` was anyway insufficient as `OsString` was not `repr(transparent)`. And furthermore, on Windows it was blatantly wrong as `OsString` wraps `Wtf8Buf` which is a `repr(Rust)` type with 2 fields: https://github.com/rust-lang/rust/blob/51a7396ad3d78d9326ee1537b9ff29ab3919556f/library/std/src/sys_common/wtf8.rs#L131-L146 So let's just be honest about what happens and add accessor methods that make this abstraction-breaking act of PathBuf visible on the APIs that it pierces through. Fixes rust-lang#124409
RalfJung
pushed a commit
to RalfJung/rust
that referenced
this issue
Apr 27, 2024
add smoke tests for basic PathBuf interactions I wrote these while debugging [this](https://github.com/rust-lang/miri-test-libstd/actions/runs/8849912635/job/24302962983); it turns out the issue is [more complicated](rust-lang#124409) but these tests still seemed worth keeping.
RalfJung
pushed a commit
to RalfJung/rust
that referenced
this issue
Apr 27, 2024
add smoke tests for basic PathBuf interactions I wrote these while debugging [this](https://github.com/rust-lang/miri-test-libstd/actions/runs/8849912635/job/24302962983); it turns out the issue is [more complicated](rust-lang#124409) but these tests still seemed worth keeping.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PathBuf contains this gem:
rust/library/std/src/path.rs
Lines 1172 to 1175 in f56afa0
This effectively transmutes an
OsString
toVec<u8>
. But on Windows,OsString
isWtf8Buf
:rust/library/std/src/sys_common/wtf8.rs
Lines 131 to 146 in 51a7396
This is not
repr(transparent)
, so there is no guarantee that we can just transmute this. And I think with layout randomization this can actually fail -- that's probably what happened here.Is there a reason why this uses transmutes rather than some sort of private accessor that exposes a
*mut Vec<u8>
through all these layers?The text was updated successfully, but these errors were encountered: