From 28ff9f7310fd459cc28279efdba9aba5e60daee2 Mon Sep 17 00:00:00 2001 From: Nameless Date: Mon, 12 Feb 2024 15:23:08 -0600 Subject: [PATCH 1/2] bug: std.os.realpath on non-windows asserts no nulls, make an error --- src/terminal/kitty/graphics_image.zig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/terminal/kitty/graphics_image.zig b/src/terminal/kitty/graphics_image.zig index fa20eaa10..7bd953ef9 100644 --- a/src/terminal/kitty/graphics_image.zig +++ b/src/terminal/kitty/graphics_image.zig @@ -75,6 +75,12 @@ pub const LoadingImage = struct { log.warn("failed to decode base64 data: {}", .{err}); return error.InvalidData; }; + + if (builtin.os != .windows and std.mem.indexOfScalar(u8, buf[0..size], 0) == null) { + // std.os.realpath *asserts* that the path does not have internal nulls instead of erroring. + log.warn("failed to get absolute path: BadPathName", .{}); + return error.InvalidData; + } var abs_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; const path = std.os.realpath(buf[0..size], &abs_buf) catch |err| { log.warn("failed to get absolute path: {}", .{err}); From 9193cfa6d2769a2a615674e0349afee529289412 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 12 Feb 2024 19:31:58 -0800 Subject: [PATCH 2/2] style nit --- src/terminal/kitty/graphics_image.zig | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/terminal/kitty/graphics_image.zig b/src/terminal/kitty/graphics_image.zig index 7bd953ef9..b5c36db80 100644 --- a/src/terminal/kitty/graphics_image.zig +++ b/src/terminal/kitty/graphics_image.zig @@ -76,11 +76,15 @@ pub const LoadingImage = struct { return error.InvalidData; }; - if (builtin.os != .windows and std.mem.indexOfScalar(u8, buf[0..size], 0) == null) { - // std.os.realpath *asserts* that the path does not have internal nulls instead of erroring. - log.warn("failed to get absolute path: BadPathName", .{}); - return error.InvalidData; + if (comptime builtin.os != .windows) { + if (std.mem.indexOfScalar(u8, buf[0..size], 0) == null) { + // std.os.realpath *asserts* that the path does not have + // internal nulls instead of erroring. + log.warn("failed to get absolute path: BadPathName", .{}); + return error.InvalidData; + } } + var abs_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; const path = std.os.realpath(buf[0..size], &abs_buf) catch |err| { log.warn("failed to get absolute path: {}", .{err});