summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 22:09:09 -0300
committerGabriel Schneider <[email protected]>2026-11-24 22:14:12 -0300
commit8c083912002f5cfdf268ed45ec217fbd8bde41d0 (patch)
treedd740093970788f6a1336ea49b66f5ee1b669924 /core
parentc1e71f6734fc0f74f1e059dda3e2841e8a69d0c4 (diff)
downloadpardes-8c083912002f5cfdf268ed45ec217fbd8bde41d0.tar.gz
pardes-8c083912002f5cfdf268ed45ec217fbd8bde41d0.zip
TagState, Core: a loaded tag state is held to what it indexes, and a told focus to the pane slots (fixes found by item 4's dump fuzz, on line A2): RUN: the 40,000-seed dump fuzz (core/fuzz.zig "a dump and an image cut...", its counts raised to 40,000 join and 1,779 image seeds and its session put in Help, `SPC t w` then `SPC ? hel`, a temporary edit put back) panicked twice before this: `index out of bounds: index 65163, len 64` at TagState.zig helpLeaf (`p.kinds.words[at - flat.len]`), from Band.helpSteps, draw.joinBand, render of a damaged dump's view, and then `index 524288, len 64` at Core.zig reportFocus (`p.panes[old.id]`); THE CAUSE: a dump gives View.tag_state as it was written, and nothing held its indexes after a load: a Help hit past the tree and the registry's words, its rows' cursor past its hits, the field's caret past its text, describe-key's found leaf with no keys; and View.focus_told (main's, unchanged since e9f3712c) is read back as a pane slot unchecked (the seeds land elsewhere since the tag state joined the dump: wire 36); THE FIX: TagState.loaded, from dump.zig afterLoad (both loads): a tag state that does not hold is at rest, its memory of leaves kept; reportFocus asks a slot past MAX_PANES for no pane; a user could hit them only with a damaged dump (a cut file, a flipped byte), and the session panicked on its first frame or key; NOT FIXED: the third run of the fuzz panicked with `double free` in walk.zig slice (walk.zig:1847, from value:1780, oneField:1988, dump.zig:422 loadKnowing: the join road): a damaged back-reference (l.ref) lets two fields share one allocation, both freed on the error path: the loader's, main's; TEST: TagState.zig "a dump's tag state that indexes past what it names is at rest when loaded, and its frame draws"
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core')
-rw-r--r--core/Core.zig3
-rw-r--r--core/TagState.zig42
-rw-r--r--core/dump.zig1
3 files changed, 45 insertions, 1 deletions
diff --git a/core/Core.zig b/core/Core.zig
index 5ce635f2..b4d6293e 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -1029,7 +1029,8 @@ fn reportFocus(p: *Pardes) void {
// program hears of it a round trip later (a write there would stop the
// speculation: pty_write is `keeps_stopping`'s).
if (p.tape.speculating) return;
- if (v.focus_told) |old| if (p.panes[old.id]) |pane| {
+ // A damaged dump's pane past the slots names none.
+ if (v.focus_told) |old| if (old.id < MAX_PANES) if (p.panes[old.id]) |pane| {
if (pane.serial == old.serial and pardes.Term.modes(pane.terminal).focus) p.emitWrite(old.id, "\x1b[O");
};
if (want) |new| if (pardes.Term.modes(p.panes[new.id].?.terminal).focus) p.emitWrite(new.id, "\x1b[I");
diff --git a/core/TagState.zig b/core/TagState.zig
index 867b1391..191aad8d 100644
--- a/core/TagState.zig
+++ b/core/TagState.zig
@@ -247,6 +247,20 @@ pub fn wake(p: *const Pardes) ?u64 {
return soonest;
}
+/// Each view's tag state as a dump gave it, held to what it indexes: Help's
+/// hits in the tree and the registry, its rows' cursor in them, the field's
+/// caret in its text, describe-key's found leaf or struck key in its keys.
+/// One that is not (a damaged dump: the fuzz's cut and flipped bytes) is
+/// at rest, its memory of leaves kept (dump.zig afterLoad).
+pub fn loaded(p: *Pardes) void {
+ for (&p.views) |*slot| if (slot.*) |*v| {
+ const s = &v.tag_state;
+ var held = s.field.caret <= s.field.len and s.nhits <= max_hits and s.rows.at < @max(1, s.nhits) and !(s.found and s.scope_n == 0) and !(s.missed and s.scope_root == null and s.scope_n == 0);
+ for (s.hits[0..@min(s.nhits, max_hits)]) |at| held = held and at < bindings.flat.len + p.kinds.nwords;
+ if (!held) s.* = .{ .used = s.used };
+ };
+}
+
/// The last leaf run in the current level, as the line under it says it
/// (Messages' leader band): `k Hover: its summary (last used here)`, while
/// the level is shown rolled.
@@ -891,3 +905,31 @@ test "a tag out of rest keeps its rows at rest at least: a root's key cell alone
try std.testing.expectEqual(tag_rows, pane.tag_rows);
try std.testing.expectEqual(@as(u16, 0), pane.tag_top);
}
+
+test "a dump's tag state that indexes past what it names is at rest when loaded, and its frame draws" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 120, .rows = 40 });
+ defer p.deinit();
+ _ = try p.setTestFile("one\n");
+ var frame = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer frame.deinit();
+ for (" ?hel") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ const s = &p.view().tag_state;
+ try std.testing.expect(s.kind == .help and s.nhits > 0);
+ loaded(p);
+ try std.testing.expect(s.kind == .help);
+ // A hit past the tree and the registry's words, as a cut dump made one.
+ s.hits[0] = 65163;
+ s.used[0] = 'q';
+ loaded(p);
+ try std.testing.expect(s.kind == .rest and s.nhits == 0 and s.used[0] == 'q');
+ _ = try p.render(frame.allocator());
+ // A caret past the field's text, a cursor past the rows.
+ for (" ?hel") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ s.field.caret = s.field.len + 1;
+ loaded(p);
+ try std.testing.expect(s.kind == .rest);
+ for (" ?hel") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } });
+ s.rows.at = s.nhits;
+ loaded(p);
+ try std.testing.expect(s.kind == .rest);
+}
diff --git a/core/dump.zig b/core/dump.zig
index b4561ae2..49b2605a 100644
--- a/core/dump.zig
+++ b/core/dump.zig
@@ -148,6 +148,7 @@ fn afterLoad(p: *Pardes) void {
f.context.reload(p.tree_sitter_gpa, f.path, text, f.revision);
};
@import("jj.zig").loaded(p);
+ pardes.TagState.loaded(p);
}
/// A file kept slim in a dump (`dumpExit`, a closed pane's past its bound,