Skip to content
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

Regression: File::open not falling back to FileEndOfFileInfo on WINE #135831

Open
MeguminSama opened this issue Jan 21, 2025 · 2 comments · May be fixed by #135837
Open

Regression: File::open not falling back to FileEndOfFileInfo on WINE #135831

MeguminSama opened this issue Jan 21, 2025 · 2 comments · May be fixed by #135837
Labels
C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@MeguminSama
Copy link

MeguminSama commented Jan 21, 2025

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.

// 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:

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

@MeguminSama MeguminSama added the C-bug Category: This is a bug. label Jan 21, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 21, 2025
@MeguminSama MeguminSama changed the title Regression - File::open not falling back to FileEndOfFileInfo on WINE Regression: File::open not falling back to FileEndOfFileInfo on WINE Jan 21, 2025
@ChrisDenton
Copy link
Member

Oh apologies it seems I left in some test code somehow. That panic message was definitely not meant to make it in to production.

@ChrisDenton ChrisDenton linked a pull request Jan 21, 2025 that will close this issue
@MeguminSama
Copy link
Author

No worries, thanks for responding so quickly :)

@saethlin saethlin added 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 Jan 21, 2025
jieyouxu added a commit to jieyouxu/rust that referenced this issue Jan 22, 2025
jieyouxu added a commit to jieyouxu/rust that referenced this issue Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants