From e658d10143206db1f726228e8e9e0a54a4b76234 Mon Sep 17 00:00:00 2001 From: salo-dea <46715729+salo-dea@users.noreply.github.com> Date: Fri, 10 Nov 2023 17:04:08 +0100 Subject: [PATCH] Do not assume that FILE_BOTH_DIR_INFORMATION is correctly aligned --- lib/std/fs.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/std/fs.zig b/lib/std/fs.zig index 6cda6716b765..8c6be197bc26 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -749,7 +749,9 @@ pub const IterableDir = struct { } } - const dir_info: *w.FILE_BOTH_DIR_INFORMATION = @ptrCast(@alignCast(&self.buf[self.index])); + // While the official api docs guarantee FILE_BOTH_DIR_INFORMATION to be aligned properly + // this may not always be the case (e.g. due to faulty VM/Sandboxing tools) + const dir_info: *align(2) w.FILE_BOTH_DIR_INFORMATION = @ptrCast(@alignCast(&self.buf[self.index])); if (dir_info.NextEntryOffset != 0) { self.index += dir_info.NextEntryOffset; } else {