| author | |
| committer | |
| log | ad08117e9daf5d2a34be1ca71a23366f39079990 |
| tree | c44d26a0a774c047a853542da3c2ba0bb9a771f4 |
| parent | fd0c324cb05d0d30f8ca5ae44f6db5072975b125 |
2 files changed, 11 insertions(+), 4 deletions(-)
lib/std/Io/Dir.zig+6-1| ... | @@ -105,7 +105,12 @@ pub const Reader = struct { | ... | @@ -105,7 +105,12 @@ pub const Reader = struct { |
| 105 | pub const min_buffer_len = switch (native_os) { | 105 | pub const min_buffer_len = switch (native_os) { |
| 106 | .linux => std.mem.alignForward(usize, @sizeOf(std.os.linux.dirent64), 8) + | 106 | .linux => std.mem.alignForward(usize, @sizeOf(std.os.linux.dirent64), 8) + |
| 107 | std.mem.alignForward(usize, max_name_bytes, 8), | 107 | std.mem.alignForward(usize, max_name_bytes, 8), |
| 108 | .windows => std.mem.alignForward(usize, max_name_bytes, @alignOf(usize)), | 108 | .windows => len: { |
| 109 | const max_info_len = @sizeOf(std.os.windows.FILE_BOTH_DIR_INFORMATION) + std.os.windows.NAME_MAX * 2; | ||
| 110 | const info_align = @alignOf(std.os.windows.FILE_BOTH_DIR_INFORMATION); | ||
| 111 | const reserved_len = std.mem.alignForward(usize, max_name_bytes, info_align) - max_info_len; | ||
| 112 | break :len std.mem.alignForward(usize, reserved_len, info_align) + max_info_len; | ||
| 113 | }, | ||
| 109 | .wasi => @sizeOf(std.os.wasi.dirent_t) + | 114 | .wasi => @sizeOf(std.os.wasi.dirent_t) + |
| 110 | std.mem.alignForward(usize, max_name_bytes, @alignOf(std.os.wasi.dirent_t)), | 115 | std.mem.alignForward(usize, max_name_bytes, @alignOf(std.os.wasi.dirent_t)), |
| 111 | else => if (builtin.link_libc) @sizeOf(std.c.dirent) else std.mem.alignForward(usize, max_name_bytes, @alignOf(usize)), | 116 | else => if (builtin.link_libc) @sizeOf(std.c.dirent) else std.mem.alignForward(usize, max_name_bytes, @alignOf(usize)), |
lib/std/Io/Threaded.zig+5-3| ... | @@ -3757,11 +3757,13 @@ fn dirReadWindows(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) D | ... | @@ -3757,11 +3757,13 @@ fn dirReadWindows(userdata: ?*anyopaque, dr: *Dir.Reader, buffer: []Dir.Entry) D |
| 3757 | // reserve enough to get us to up to having `3 * NAME_MAX` bytes available when taking into account | 3757 | // reserve enough to get us to up to having `3 * NAME_MAX` bytes available when taking into account |
| 3758 | // that we have the ability to write over top of the reserved memory + the full footprint of that | 3758 | // that we have the ability to write over top of the reserved memory + the full footprint of that |
| 3759 | // particular `FILE_BOTH_DIR_INFORMATION`. | 3759 | // particular `FILE_BOTH_DIR_INFORMATION`. |
| 3760 | const reserve_needed = w.NAME_MAX - @sizeOf(w.FILE_BOTH_DIR_INFORMATION); | 3760 | const max_info_len = @sizeOf(w.FILE_BOTH_DIR_INFORMATION) + w.NAME_MAX * 2; |
| 3761 | const unreserved_start = std.mem.alignForward(usize, reserve_needed, @alignOf(usize)); | 3761 | const info_align = @alignOf(w.FILE_BOTH_DIR_INFORMATION); |
| 3762 | const reserve_needed = std.mem.alignForward(usize, Dir.max_name_bytes, info_align) - max_info_len; | ||
| 3763 | const unreserved_start = std.mem.alignForward(usize, reserve_needed, info_align); | ||
| 3762 | const unreserved_buffer = dr.buffer[unreserved_start..]; | 3764 | const unreserved_buffer = dr.buffer[unreserved_start..]; |
| 3763 | // This is enforced by `Dir.Reader` | 3765 | // This is enforced by `Dir.Reader` |
| 3764 | assert(unreserved_buffer.len >= @sizeOf(w.FILE_BOTH_DIR_INFORMATION) + w.NAME_MAX * 2); | 3766 | assert(unreserved_buffer.len >= max_info_len); |
| 3765 | 3767 | ||
| 3766 | var name_index: usize = 0; | 3768 | var name_index: usize = 0; |
| 3767 | var buffer_index: usize = 0; | 3769 | var buffer_index: usize = 0; |