From d08098861f47fb0974066fce8cc3af7d5709d12f Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Thu, 8 Jan 2026 02:18:43 -0800 Subject: [PATCH] Fix RENAME_INFORMATION.toBuffer returning sizes below the minimum recognized size Passing a length below 24 to NtSetInformationFile results in INFO_LENGTH_MISMATCH, so always return at least 24 for the buffer length. --- lib/std/os/windows.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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]; } }; -- 2.54.0