zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit ad08117e9daf5d2a34be1ca71a23366f39079990 (tree)
parent fd0c324cb05d0d30f8ca5ae44f6db5072975b125
Author: Ryan Liptak <squeek502@hotmail.com>
Date:   Sat, 20 Dec 2025 20:15:14 -0800

Fix sizing of buffer/reservation size for dirReadWindows

Diffstat:
Mlib/std/Io/Dir.zig | 7++++++-
Mlib/std/Io/Threaded.zig | 8+++++---
2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/std/Io/Dir.zig b/lib/std/Io/Dir.zig @@ -105,7 +105,12 @@ pub const Reader = struct { pub const min_buffer_len = switch (native_os) { .linux => std.mem.alignForward(usize, @sizeOf(std.os.linux.dirent64), 8) + std.mem.alignForward(usize, max_name_bytes, 8), - .windows => std.mem.alignForward(usize, max_name_bytes, @alignOf(usize)), + .windows => len: { + const max_info_len = @sizeOf(std.os.windows.FILE_BOTH_DIR_INFORMATION) + std.os.windows.NAME_MAX * 2; + const info_align = @alignOf(std.os.windows.FILE_BOTH_DIR_INFORMATION); + const reserved_len = std.mem.alignForward(usize, max_name_bytes, info_align) - max_info_len; + break :len std.mem.alignForward(usize, reserved_len, info_align) + max_info_len; + }, .wasi => @sizeOf(std.os.wasi.dirent_t) + std.mem.alignForward(usize, max_name_bytes, @alignOf(std.os.wasi.dirent_t)), else => if (builtin.link_libc) @sizeOf(std.c.dirent) else std.mem.alignForward(usize, max_name_bytes, @alignOf(usize)), diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig @@ -3757,11 +3757,13 @@ fn dirReadWindows(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) D // reserve enough to get us to up to having `3 * NAME_MAX` bytes available when taking into account // that we have the ability to write over top of the reserved memory + the full footprint of that // particular `FILE_BOTH_DIR_INFORMATION`. - const reserve_needed = w.NAME_MAX - @sizeOf(w.FILE_BOTH_DIR_INFORMATION); - const unreserved_start = std.mem.alignForward(usize, reserve_needed, @alignOf(usize)); + const max_info_len = @sizeOf(w.FILE_BOTH_DIR_INFORMATION) + w.NAME_MAX * 2; + const info_align = @alignOf(w.FILE_BOTH_DIR_INFORMATION); + const reserve_needed = std.mem.alignForward(usize, Dir.max_name_bytes, info_align) - max_info_len; + const unreserved_start = std.mem.alignForward(usize, reserve_needed, info_align); const unreserved_buffer = dr.buffer[unreserved_start..]; // This is enforced by `Dir.Reader` - assert(unreserved_buffer.len >= @sizeOf(w.FILE_BOTH_DIR_INFORMATION) + w.NAME_MAX * 2); + assert(unreserved_buffer.len >= max_info_len); var name_index: usize = 0; var buffer_index: usize = 0;