From 6dcf95139118ec7e91222f7e15f5ea07a51c67f3 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 26 Dec 2025 14:45:41 -0800 Subject: [PATCH] std.Io.Threaded: error instead of assert for statx when statx fails to return some of the requested fields --- lib/std/Io/Threaded.zig | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index 18ee2c920611fbc000331e41e382b32112fb1127..c5e0415ad16c37e5a9836cc933c101ac759ff55d 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -2086,6 +2086,7 @@ fn fileLength(userdata: ?*anyopaque, file: File) File.LengthError!u64 { switch (linux.errno(linux.statx(file.handle, "", linux.AT.EMPTY_PATH, .{ .SIZE = true }, &statx))) { .SUCCESS => { current_thread.endSyscall(); + if (!statx.mask.SIZE) return error.Unexpected; return statx.size; }, .INTR => { @@ -5431,7 +5432,7 @@ fn fchmodatFallback( switch (sys.errno(sys.statx(path_fd, "", posix.AT.EMPTY_PATH, .{ .TYPE = true }, &statx))) { .SUCCESS => { current_thread.endSyscall(); - assert(statx.mask.TYPE); + if (!statx.mask.TYPE) return error.Unexpected; break statx.mode; }, .INTR => { @@ -11112,15 +11113,15 @@ fn clockToWasi(clock: Io.Clock) std.os.wasi.clockid_t { }; } -fn statFromLinux(stx: *const std.os.linux.Statx) File.Stat { - assert(stx.mask.TYPE); - assert(stx.mask.MODE); - assert(stx.mask.ATIME); - assert(stx.mask.MTIME); - assert(stx.mask.CTIME); - assert(stx.mask.INO); - assert(stx.mask.SIZE); - assert(stx.mask.NLINK); +fn statFromLinux(stx: *const std.os.linux.Statx) Io.UnexpectedError!File.Stat { + if (!stx.mask.TYPE) return error.Unexpected; + if (!stx.mask.MODE) return error.Unexpected; + if (!stx.mask.ATIME) return error.Unexpected; + if (!stx.mask.MTIME) return error.Unexpected; + if (!stx.mask.CTIME) return error.Unexpected; + if (!stx.mask.INO) return error.Unexpected; + if (!stx.mask.SIZE) return error.Unexpected; + if (!stx.mask.NLINK) return error.Unexpected; const atime = stx.atime; const mtime = stx.mtime; const ctime = stx.ctime; -- 2.54.0