From 18933ab34ea07f2cf755aa4e8d9bdb4dc25a67a6 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 23 Nov 2026 15:41:12 -0300 Subject: the boundaries fuzzes and tests, failing first: bytes from outside (garbage and mutated-valid) into the reader that takes them, a fixed seed list and seconds, an error never a panic, memory held by a capped allocator (core/fuzz.zig, in core-test): 9P frames through the engine pardes runs (`runtime.ninep.Server(pardes.ctlfs, runtime.ninep.editor)`), framed as the engine frames them so that no walk reaches `os` (the host files) or `n`, the core effects dropped, a frame drawn after each push (16 seeds x 400 frames, deep: 607 writes, 604 reads in one run); a client inputs into the session reader (`replica.parseInput`, every tag decodeClient) applied with `update` and drawn; a session units recorded by an `Authority`, cut, flipped and grown, replayed by a `Replica` (the client road); a session byte dump and image, damaged, through `dump.check` and `dump.load`; and the sites the note found by reading, each a test: a +Search pane rows style past the syntax kinds (`m 1 1 0 0 0 0 0 3:0+3=7 a.txt`), a Grep row of a file named `a:5000000000:b` (core/Query.zig), a top-down BMP (its height negative, addons/image/image.zig, addon-test), an X10 mouse report with a control byte and an SGR one with button 192 (dev/tui/tui.zig, shell-test); on main (f34d3a74cc4a), Debug, each alone: the rows test `expected .err, found .ok` (drawn: `invalid enum value` at core/File.zig:2079), the session side `integer overflow` at core/draw.zig:282 (joinNotice, a prompt caret on a band of 65535 glyphs: Layer.capacity under a client row metrics), the client side `invalid enum value` at core/tape.zig:458 (`peek`), the Grep row `integer does not fit` at core/Query.zig:1267, the BMP `integer does not fit` (image.zig `info`), the X10 report `integer overflow` at vaxis Parser.zig:792; the 9P fuzz and the dump fuzz pass on main (no panic reached) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- addons/image/image.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'addons/image/image.zig') diff --git a/addons/image/image.zig b/addons/image/image.zig index f2303433..48135458 100644 --- a/addons/image/image.zig +++ b/addons/image/image.zig @@ -137,3 +137,19 @@ test "a job decodes a picture to its size and pixels, and one past max_dim is sc try std.testing.expectEqual(8 + 1280 * 4, wide.len); try std.testing.expect(Image.jobRun("not a picture", arena.allocator()) == null); } + +test "a top-down BMP (its height negative in its header) opens at its size, as any picture" { + var arena: std.heap.ArenaAllocator = .init(std.testing.allocator); + defer arena.deinit(); + // 2x2, 24 bits, biHeight -2: rows top first, each 6 bytes and 2 of padding. + const bmp = "BM" ++ "\x46\x00\x00\x00" ++ "\x00\x00\x00\x00" ++ "\x36\x00\x00\x00" ++ + "\x28\x00\x00\x00" ++ "\x02\x00\x00\x00" ++ "\xfe\xff\xff\xff" ++ "\x01\x00" ++ "\x18\x00" ++ + "\x00\x00\x00\x00" ++ "\x10\x00\x00\x00" ++ "\x13\x0b\x00\x00" ++ "\x13\x0b\x00\x00" ++ "\x00\x00\x00\x00" ++ "\x00\x00\x00\x00" ++ + "\x00\x00\xff\x00\xff\x00\x00\x00" ++ "\xff\x00\x00\xff\xff\xff\x00\x00"; + try std.testing.expectEqual([2]u32{ 2, 2 }, info(bmp).?); + const got = Image.jobRun(bmp, arena.allocator()).?; + try std.testing.expectEqual(8 + 2 * 2 * 4, got.len); + try std.testing.expectEqual(2, std.mem.readInt(u32, got[4..8], .little)); + // Its first pixel is the top row's first: red (BGR 00 00 ff). + try std.testing.expectEqualSlices(u8, &.{ 0xff, 0, 0, 0xff }, got[8..12]); +} -- cgit v1.3 From 60c428d74f8aad24d002a674d95a95de9c5ee76b Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 23 Nov 2026 16:13:35 -0300 Subject: image: a top-down BMP opens: stb's info gives its height negative (its loader takes the length), and addons/image/image.zig cast it to u32 (`integer does not fit`, in the session at the pane's open, on main: the test of the change before); now `size` (no size: nothing to show; a negative height its length), and a job copies the pixels by the load's own size, refusing a load whose size is not info's (it copied by info's); a user could hit it by opening a valid BMP Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- addons/image/image.zig | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'addons/image/image.zig') diff --git a/addons/image/image.zig b/addons/image/image.zig index 48135458..8e2cb32a 100644 --- a/addons/image/image.zig +++ b/addons/image/image.zig @@ -33,7 +33,14 @@ fn info(bytes: []const u8) ?[2]u32 { defer job = null; var w: c_int, var h: c_int = .{ 0, 0 }; if (bytes.len == 0 or bytes.len > std.math.maxInt(c_int) or pa_image_info(bytes.ptr, @intCast(bytes.len), &w, &h) == 0) return null; - return .{ @intCast(w), @intCast(h) }; + return size(w, h); +} + +/// stb's width and height as a size: a top-down BMP's height is negative in +/// its info (stb's loader takes the length of it); none, nothing to show. +fn size(w: c_int, h: c_int) ?[2]u32 { + if (w <= 0 or h == 0) return null; + return .{ @intCast(w), @abs(h) }; } /// Each pane's pixels in this process, by its block's address: a draw's @@ -83,9 +90,12 @@ pub const Image = extern struct { defer job = null; var w: c_int, var h: c_int = .{ 0, 0 }; if (in.len == 0 or in.len > std.math.maxInt(c_int) or pa_image_info(in.ptr, @intCast(in.len), &w, &h) == 0) return null; - const wh: [2]u32 = .{ @intCast(w), @intCast(h) }; + const wh = size(w, h) orelse return null; if (@as(u64, wh[0]) * wh[1] > max_pixels) return null; var px = pa_image_load(in.ptr, @intCast(in.len), &w, &h) orelse return null; + // The pixels are the load's: copied by its size, never info's alone. + const loaded = size(w, h) orelse return null; + if (loaded[0] != wh[0] or loaded[1] != wh[1]) return null; const longest: u64 = @max(wh[0], wh[1]); var nw, var nh = wh; if (longest > max_dim) { -- cgit v1.3