From c9dfcd27811303b71ffb689917dfe13c19333004 Mon Sep 17 00:00:00 2001 From: David Leadbeater Date: Fri, 3 Jan 2025 11:12:33 +1100 Subject: [PATCH] kittygfx: Ensure temporary files are named per spec Temporary files used with Kitty graphics must have "tty-graphics-protocol" somewhere in their full path. https://sw.kovidgoyal.net/kitty/graphics-protocol/#the-transmission-medium --- src/terminal/kitty/graphics_exec.zig | 1 + src/terminal/kitty/graphics_image.zig | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/terminal/kitty/graphics_exec.zig b/src/terminal/kitty/graphics_exec.zig index cc87d6c9d..25c819b10 100644 --- a/src/terminal/kitty/graphics_exec.zig +++ b/src/terminal/kitty/graphics_exec.zig @@ -382,6 +382,7 @@ fn encodeError(r: *Response, err: EncodeableError) void { error.DecompressionFailed => r.message = "EINVAL: decompression failed", error.FilePathTooLong => r.message = "EINVAL: file path too long", error.TemporaryFileNotInTempDir => r.message = "EINVAL: temporary file not in temp dir", + error.TemporaryFileNotNamedCorrectly => r.message = "EINVAL: temporary file not named correctly", error.UnsupportedFormat => r.message = "EINVAL: unsupported format", error.UnsupportedMedium => r.message = "EINVAL: unsupported medium", error.UnsupportedDepth => r.message = "EINVAL: unsupported pixel depth", diff --git a/src/terminal/kitty/graphics_image.zig b/src/terminal/kitty/graphics_image.zig index ff498cbb8..7a107208b 100644 --- a/src/terminal/kitty/graphics_image.zig +++ b/src/terminal/kitty/graphics_image.zig @@ -220,6 +220,9 @@ pub const LoadingImage = struct { // Temporary file logic if (medium == .temporary_file) { if (!isPathInTempDir(path)) return error.TemporaryFileNotInTempDir; + if (std.mem.indexOf(u8, path, "tty-graphics-protocol") == null) { + return error.TemporaryFileNotNamedCorrectly; + } } defer if (medium == .temporary_file) { posix.unlink(path) catch |err| { @@ -469,6 +472,7 @@ pub const Image = struct { DimensionsTooLarge, FilePathTooLong, TemporaryFileNotInTempDir, + TemporaryFileNotNamedCorrectly, UnsupportedFormat, UnsupportedMedium, UnsupportedDepth,