From 4393f4e376be1c93a2e611f4d6a6aa83420ba5b9 Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Thu, 18 Jun 2026 06:49:55 -0700 Subject: [PATCH] fix(windows): use EndOfFile instead of AllocationSize for UWP file size On UWP targets, File::metadata().len() returns AllocationSize from FILE_STANDARD_INFO, which is the disk space allocated (rounded to cluster size), not the actual file size. A 1-byte file on a 4K-cluster NTFS volume would report len() as 4096. Use EndOfFile instead, which is the actual end-of-file position matching the non-UWP path. Signed-off-by: Sebastien Tardif --- library/std/src/sys/fs/windows.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/fs/windows.rs b/library/std/src/sys/fs/windows.rs index fef3c0665eda1..e3e7b081b47d5 100644 --- a/library/std/src/sys/fs/windows.rs +++ b/library/std/src/sys/fs/windows.rs @@ -597,7 +597,7 @@ impl File { (&raw mut info) as *mut c_void, size as u32, ))?; - attr.file_size = info.AllocationSize as u64; + attr.file_size = info.EndOfFile as u64; attr.number_of_links = Some(info.NumberOfLinks); if attr.attributes & c::FILE_ATTRIBUTE_REPARSE_POINT != 0 { let mut attr_tag: c::FILE_ATTRIBUTE_TAG_INFO = mem::zeroed();