summaryrefslogtreecommitdiff
path: root/src/ninep/ctl.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-29 12:31:47 -0300
committerGabriel Schneider <[email protected]>2026-10-01 00:12:16 -0300
commita5be027a0c05c8950bada14fa2f2e713ce7d6986 (patch)
tree8eecd0fd54ef077baf1239f5f00277329974ee95 /src/ninep/ctl.zig
parent549cfa40e99c3d1937b742a0dba043281c687c83 (diff)
downloadpardes-a5be027a0c05c8950bada14fa2f2e713ce7d6986.tar.gz
pardes-a5be027a0c05c8950bada14fa2f2e713ce7d6986.zip
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: <path>: not an image pardes can read, making no pane. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/ninep/ctl.zig')
-rw-r--r--src/ninep/ctl.zig22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index be90bb6f..978ce707 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -2115,6 +2115,28 @@ test "a language server question that finds nothing, cannot be answered, or is a
try testing.expectEqual(E.INVAL, wr(p, Node.of(img.serial, .body), "text\n").errno());
}
+test "a corrupt image fails its look with an err, and no pane is made" {
+ pardes.image.start(testing.io, testing.allocator);
+ defer pardes.image.stop();
+ const p = try withFile(testing.allocator, "x\n");
+ defer p.deinit();
+ var tmp = testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(testing.io, .{ .sub_path = "bad.png", .data = "\x89PNG not really" });
+ var dir_buf: [4096]u8 = undefined;
+ const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
+ var line: [4200]u8 = undefined;
+ var count: usize = 0;
+ for (p.panes) |slot| count += @intFromBool(slot != null);
+ const r = wr(p, root_look, try std.fmt.bufPrint(&line, "{s}/bad.png\n", .{dir}));
+ try testing.expectEqual(E.IO, r.errno());
+ try testing.expect(std.mem.endsWith(u8, r.reply.ename, "bad.png: not an image pardes can read"));
+ p.sync();
+ var after: usize = 0;
+ for (p.panes) |slot| after += @intFromBool(slot != null);
+ try testing.expectEqual(count, after);
+}
+
test "a PDF's body reads its page's text layer, and takes no write" {
if (comptime !pardes.pdf_enabled) return;
const p = try withFile(testing.allocator, "x\n");