-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Description
As of what appears to be this commit ca56dc8, nightly crashes on WINE when running File::open
.
The issue appears to be that SetFileInformationByHandle returns 0
when it fails, and expects you to run GetLastError
to get the error code.
In the code for File::open
, there is a comment block explaining that this should fall back to using FileEndOfFileInfo
if it fails, for WINE support.
rust/library/std/src/sys/pal/windows/fs.rs
Lines 319 to 322 in cd805f0
// This first tries `FileAllocationInfo` but falls back to | |
// `FileEndOfFileInfo` in order to support WINE. | |
// If WINE gains support for FileAllocationInfo, we should | |
// remove the fallback. |
However from this commit, the code will panic if the result of api::get_last_error().code != 0
, meaning it will always panic if FileAllocationInfo
fails, and will never attempt to use FileEndOfFileInfo
.
Relevant source code:
rust/library/std/src/sys/pal/windows/fs.rs
Lines 331 to 340 in cd805f0
if api::get_last_error().code != 0 { | |
panic!("FILE_ALLOCATION_INFO failed!!!"); | |
} | |
let eof = c::FILE_END_OF_FILE_INFO { EndOfFile: 0 }; | |
let result = c::SetFileInformationByHandle( | |
handle.as_raw_handle(), | |
c::FileEndOfFileInfo, | |
(&raw const eof).cast::<c_void>(), | |
mem::size_of::<c::FILE_END_OF_FILE_INFO>() as u32, | |
); |
I tried this code:
fn main() {
std::fs::write("testing.txt", "Hello world").unwrap();
}
I expected to see this happen: Hello world
should be written to testing.txt
Instead, this happened: Rust panics with a backtrace.
Meta
rustc --version --verbose
:
rustc 1.86.0-nightly (f3d1d47fd 2025-01-20)
binary: rustc
commit-hash: f3d1d47fd84dfcf7f513be1dbad356e74c8f3b2b
commit-date: 2025-01-20
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7
This does not occur on stable. Reverting to nightly-2024-12-23
also works fine.
Backtrace
cargo xwin run --target x86_64-pc-windows-msvc
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.00s
Running `wine target/x86_64-pc-windows-msvc/debug/rusttest.exe`
wineserver: using server-side synchronization.
wine: Using setpriority to control niceness in the [-10,10] range
thread 'main' panicked at library\std\src\sys\pal\windows\fs.rs:332:29:
FILE_ALLOCATION_INFO failed!!!
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace