Skip to content

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

@MeguminSama

Description

@MeguminSama

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

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jan 21, 2025
changed the title [-]Regression - File::open not falling back to FileEndOfFileInfo on WINE[/-] [+]Regression: `File::open` not falling back to `FileEndOfFileInfo` on WINE[/+] on Jan 21, 2025
ChrisDenton

ChrisDenton commented on Jan 21, 2025

@ChrisDenton
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.

MeguminSama

MeguminSama commented on Jan 21, 2025

@MeguminSama
Author

No worries, thanks for responding so quickly :)

added
T-libsRelevant to the library team, which will review and decide on the PR/issue.
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jan 21, 2025
added 2 commits that reference this issue on Jan 22, 2025
127bc47
e4f6895
added 2 commits that reference this issue on Jan 22, 2025
caf38c7
0bdc101
added a commit that references this issue on Mar 11, 2025
0988d26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @ChrisDenton@saethlin@MeguminSama@rustbot

      Issue actions

        Regression: `File::open` not falling back to `FileEndOfFileInfo` on WINE · Issue #135831 · rust-lang/rust