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 --- core/Query.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'core/Query.zig') diff --git a/core/Query.zig b/core/Query.zig index 2ffcfd3b..fe25d5fd 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -2746,3 +2746,14 @@ test "a query row's address reaches every way a look arrives: an empty look writ try std.testing.expectEqual(tree.Status.ok, @import("ninep/harness.zig").wr(p, tree.Node.of(qp.serial, .look), line).reply.status); try std.testing.expectEqual(@as(i32, 3), a.body.cur_row); } + +test "Grep: a row whose numbers a Found cannot hold (a column past u32) is passed over, never cast" { + const gpa = std.testing.allocator; + const p = try @import("ninep/harness.zig").withFile(gpa, "x\n"); + defer p.deinit(); + var q: Query = .{ .owner = 0 }; + defer q.deinit(p.gpa); + take(p, &q, .grep, "a:5000000000:b:3:1-4 hit\nok.txt:2:3-5 hit\nb:7:4294967297 hit\n"); + // Taken or passed over, each: never cast (main: Query.zig:1267). + try std.testing.expect(q.found.items.len <= 3); +} -- cgit v1.3 From 5a7716d32de84255e792c5f4bf0fa7b8261b9139 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 23 Nov 2026 16:13:35 -0300 Subject: Grep: a row whose numbers a Found cannot hold is passed over: a row is a line's text with the file's name in it, and core/Query.zig take narrowed its line, column, end and path length by `@intCast`: a row `b:7:4294967297 hit` (a column past u32: a long line's hit, or a name made of such numbers) panicked every process (`integer does not fit` at Query.zig:1267 on main, the test of the tests change); now `std.math.cast` each, the row passed over; the survey's example, a file named `a:5000000000:b`, is no fault: the name parses whole; not fixed: the name unescaped (a newline in a name injects a row) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/Query.zig | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'core/Query.zig') diff --git a/core/Query.zig b/core/Query.zig index fe25d5fd..7bc30c9d 100644 --- a/core/Query.zig +++ b/core/Query.zig @@ -1257,19 +1257,21 @@ pub fn take(p: *Pardes, q: *Query, kind: Stream.Kind, rows: []const u8) void { const t = look.parsePathLine(ln); if (t.at.line == 0 or t.path.len == 0) continue; const code = if (t.end < ln.len) ln[t.end + 1 ..] else ""; - const path_at: u32 = @intCast(q.found_bytes.items.len); + // A row is a line's text, a file's name in it unescaped (one + // named `a:5000000000:b` reads as `a` at line 5000000000): one + // whose numbers a Found cannot hold is passed over. + const found: Found = .{ + .path = std.math.cast(u32, q.found_bytes.items.len) orelse return, + .path_len = std.math.cast(u16, t.path.len) orelse continue, + .line = std.math.cast(u32, t.at.line) orelse continue, + .col = std.math.cast(u32, t.at.col -| 1) orelse continue, + .end = std.math.cast(u32, if (t.at.end_col > 0) t.at.end_col else t.at.col) orelse continue, + .code = std.math.cast(u32, q.found_bytes.items.len + t.path.len) orelse return, + .code_len = std.math.cast(u32, code.len) orelse continue, + }; q.found_bytes.appendSlice(p.gpa, t.path) catch return; - const code_at: u32 = @intCast(q.found_bytes.items.len); q.found_bytes.appendSlice(p.gpa, code) catch return; - q.found.append(p.gpa, .{ - .path = path_at, - .path_len = @intCast(t.path.len), - .line = @intCast(t.at.line), - .col = @intCast(t.at.col -| 1), - .end = @intCast(if (t.at.end_col > 0) t.at.end_col else t.at.col), - .code = code_at, - .code_len = @intCast(code.len), - }) catch return; + q.found.append(p.gpa, found) catch return; }, } } -- cgit v1.3