diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index a96334add99833f02b85874ac6d2aa65f8903417..a1512e6e4f67adefe593ccbf0ca72300015b2712 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -267,7 +267,11 @@ pub const FILE = struct { pub fn toBuffer(fri: *const RENAME_INFORMATION) []const u8 { const start: [*]const u8 = @ptrCast(fri); - return start[0 .. @offsetOf(RENAME_INFORMATION, "FileName") + fri.FileNameLength]; + // The ABI size of the documented struct is 24 bytes, and attempting to use any size + // less than that will trigger INFO_LENGTH_MISMATCH, so enforce a minimum in cases where, + // for example, FileNameLength is 1 so only 22 bytes are technically needed. + const size = @max(24, @offsetOf(RENAME_INFORMATION, "FileName") + fri.FileNameLength); + return start[0..size]; } };