From a5be027a0c05c8950bada14fa2f2e713ce7d6986 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 12:31:47 -0300 Subject: A look at a corrupt image fails with an err rather than open a blank pane An image stb_image could not read opened as an empty image pane, the look succeeding. The bytes' header is now checked at the look (stbi_info_from_memory), and one that is no image it reads fails the look, look: : not an image pardes can read, making no pane. Co-Authored-By: Claude Opus 5.5 --- src/look.zig | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/look.zig') diff --git a/src/look.zig b/src/look.zig index 6f279769..5cf26240 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1572,8 +1572,17 @@ pub fn lookAt(p: *Pardes, id: usize, operand: []const u8) void { .image => |target| { if (focusPaneByPath(p, target.path, .{})) return; const free = p.freeSlot() orelse return p.reportError(id, "look", error.NoPaneSlots); - _ = panes.Image.create(p, free, target.path, &.{}) catch |err| + const made = panes.Image.create(p, free, target.path, &.{}) catch |err| return p.reportError(id, if (@import("Messages.zig").dialReason(err) != null) target.path else "look", err); + // One it cannot read (corrupt, truncated, not what its name says) + // is said, a failure, rather than shown as a blank pane. + if (!@import("image.zig").readable(made.image.?.raw)) { + made.vweight = 0; + p.unplaced.set(free); + var said: [miss_path_cap + 64]u8 = undefined; + var cut: [miss_path_cap + "…".len]u8 = undefined; + return p.reportFailure(id, std.fmt.bufPrint(&said, "look: {s}: not an image pardes can read", .{missText(target.path, &cut)}) catch "look: not an image pardes can read"); + } exec.placeNew(p, id, id, free, .doc); }, } -- cgit v1.3