authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-01-08 02:18:43-08:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-01-11 02:07:49-08:00
logd08098861f47fb0974066fce8cc3af7d5709d12f
treee8836ef174846ef9b9721c44f50d3d9e0e3446a0
parentc4345991340af5ff2e0155a9832f4eed9ec677fc

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.

1 files changed, 5 insertions(+), 1 deletions(-)

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