Skip to content

Windows File::truncate silently wraps u64 > i64::MAX to negative EOF #589

Description

@SebTardif

Bug

library/std/src/sys/fs/windows.rs File::truncate does size as i64 for FILE_END_OF_FILE_INFO::EndOfFile. Values above i64::MAX wrap to negative sizes, which is not a valid user-facing contract.

Origin

Windows FS port used a direct cast; Unix uses try_into() for off_t/off64_t and returns InvalidInput on overflow.

Impact

Caller-controlled sizes from untrusted configs/protocols (object stores, archives, IPC) can pass huge u64 values and get wrong/erroneous truncation behavior instead of a clean error. Availability/correctness issue on Windows only.

Fix

size.try_into::<i64>() with io::ErrorKind::InvalidInput on failure, matching Unix.

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions