-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.
Description
I think symlink_junction_inner
sometimes isn't writing to the buffer properly which can cause the DeviceIoControl
to fail and thus tests that use it. This function isn't great and is only used in tests. I can reproduce this consistently locally on current master but in CI most PRs seem to test ok (though not all).
I've not really investigated yet but on a hunch I added the following which seems to fix it locally, I don't know why or if it's a fluke:
diff --git a/library/std/src/sys/windows/fs.rs b/library/std/src/sys/windows/fs.rs
index 37809803828..d7f1a44bdf4 100644
--- a/library/std/src/sys/windows/fs.rs
+++ b/library/std/src/sys/windows/fs.rs
@@ -1409,6 +1409,8 @@ fn symlink_junction_inner(original: &Path, junction: &Path) -> io::Result<()> {
(*db).ReparseTargetLength = ((i - 1) * 2) as c::WORD;
(*db).ReparseDataLength = (*db).ReparseTargetLength as c::DWORD + 12;
+ crate::hint::black_box(slice::from_raw_parts(buf, i));
+
let mut ret = 0;
cvt(c::DeviceIoControl(
h as *mut _,
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
workingjubilee commentedon Feb 10, 2023
cursed.
symlink_junction
#107885ChrisDenton commentedon Feb 10, 2023
Huh, simplifying that change to
crate::hint::black_box(buf);
seems to work. So I guess it just needs something to touch that pointer that it can't optimize.ChrisDenton commentedon Feb 10, 2023
I had another quick thought and replaced the
for
loop with thefor_each
iterator function. That seems to fix it too. Some bad interaction between iterators and loops perhaps?clubby789 commentedon Feb 10, 2023
The IOCTL docs don't state the type that should be passed, but links to
REPARSE_DATA_BUFFER
. This structure (with theMountPointReparseBuffer
union member) is somewhat similar to our struct, but is definitely different. So it might be that we're just passing a wrongly laid out structure which would explain differing behaviour on different machines.EDIT: Looks similar to this Wine patch.
ChrisDenton commentedon Feb 10, 2023
Hm, this has been the same since forever in Rust so it'd be surprising for it to suddenly break now.
Oh! But now I've woken up I realised something. We're not zeroing the structure. I can't believe I missed that! So we're likely putting random data into the reserved parameters.
REPARSE_MOUNTPOINT_DATA_BUFFER
header #107900ChrisDenton commentedon Feb 10, 2023
But yes, this function is awful and should be rewritten. Good job it's only used in tests...
Rollup merge of rust-lang#107900 - ChrisDenton:zero-header, r=thomcc
pub
topub(crate)
instd
#107901