diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-25 00:47:36 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-25 01:03:16 -0300 |
| commit | c26745ef409483d0b101131725a135bb5b3c5e7b (patch) | |
| tree | b472f85ecfc49f2efdb1d87c9c31adbd247a9b4a /core | |
| parent | fc45a7c8ed3b279a803dd8daad81329920b0493e (diff) | |
| download | pardes-c26745ef409483d0b101131725a135bb5b3c5e7b.tar.gz pardes-c26745ef409483d0b101131725a135bb5b3c5e7b.zip | |
dump: a byte dump's views not live keep the ranges beside their primaries: loaded, each share's `sels` is the core's, which `views.undumped` gave it (or freed it, a share refused), and the load no longer frees it after: line B's ozlumvqo (the same hunks are A2's ztzvvwkk) freed everything the load made after the core's views were read (`l.shared.items[at..]`), which took each kept share's selection buffer from under the view that holds it; found by the 5-client soak on the walk UI's merged tree M1 (xvnytwqm); RUN FIRST: `zig build replicas -Dplatform=tui -- --clients 5`: `double free or corruption (out)` at seed 0 rtt 30 (glibc, in a client's replica: Replica.confirm, replayUnit, keys.handleKey, normal.textKey, edit.handleInsert, normal.replaySels, Text.setRanges, Text.setRange, Text.dropSels (Text.zig:158), rollback.Epoch.free; the core dump shows the pointer freed inside an 80x21 surface's cell buffer allocated since: a selection buffer freed before and its memory taken again); with the replica cores' allocations on a SafeAllocator over pages (a diagnostic, not kept): `Segmentation fault` reading `pane.body.sels[si]` (body_layer.zig:397, renderBody) in a client's first draw after its join (replicas.zig joined, client.zig draw, views.drawOne, Pardes.render); and dump.zig's new test, a session whose view 0 has a second cursor, dumped (byteDump, a join's) while view 1 is live and loaded: `Segmentation fault` in Text.deinit freeing the parked view's `sels` at the loaded core's deinit (freed already by the load); THE CAUSE: dump.zig:457 (loadKnowing, after `views.undumped(p, others)`) freed every allocation the read of the shares made, the containers (`others`, each `o.panes`) and each share's `pv.body.sels` alike, though `undumped` (views.zig:134) puts each kept share's PaneView, its `sels` slice with it, into `pane.pv[k]`, and frees a refused one's itself: the core's parked views held freed buffers (a draw read them, a view's keys wrote and freed them again); THE FIX: before freeing what it made, the load drops each share's `sels` allocation from that list; the containers are still freed by what the read made, not by hand (ozlumvqo's point: a damaged dump's reference to a slice the core holds is never freed here); a user could hit it: a client joining a session where another client's view (not the one live when the join's dump is made) has more than one cursor: the joining client's core holds that view's freed ranges, and its process aborts or its replica diverges once that view's input is replayed or drawn; TEST: dump.zig 'a byte dump's views not live keep the ranges beside their primaries: loaded, the core holds them, each freed once' (fails before: the segmentation fault above, passes now); the 5-client soak clean (rtt 30/80/207: diverged 0, unequal 0, quiet checks 517/0, 428/0, 611/0, stops off may_wait 0, corpus 22 of 22, no leaks; 710 s); the fuzz at 40,000 join and 1,779 image seeds green in 154 s
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core')
| -rw-r--r-- | core/dump.zig | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/core/dump.zig b/core/dump.zig index 06a3eae5..6ba00c7f 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -454,7 +454,11 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: else => return err, }; views.undumped(p, others); - // What it made, as the mounts' (above). + // What it made, as the mounts' (above), but each share's ranges + // beside its primary: `undumped` gave them to the core, or freed them. + for (others) |o| for (o.panes) |sh| for (l.shared.items[at..]) |*m| { + if (sh.pv.body.sels.len > 0 and @intFromPtr(m.bytes.ptr) == @intFromPtr(sh.pv.body.sels.ptr)) m.bytes = &.{}; + }; for (l.shared.items[at..]) |m| if (m.bytes.len > 0) m.gpa.rawFree(m.bytes, m.alignment, @returnAddress()); l.shared.shrinkRetainingCapacity(at); afterLoad(p); @@ -1440,3 +1444,26 @@ test "a load refused after the core frees what a script's open held once: the ro // refuses the load there. try std.testing.expectError(error.MountConflict, load(gpa, .{ .mounts = &.{.{ .name = "peer", .dial = "/tmp/other.sock" }} }, bytes, null)); } + +test "a byte dump's views not live keep the ranges beside their primaries: loaded, the core holds them, each freed once" { + const gpa = std.testing.allocator; + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }); + defer p.deinit(); + const pane = try p.setTestFile("one\ntwo\nthree\nfour\n"); + // A second cursor below, and a key typed in insert mode at both. + for ("Cix") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); + p.update(.{ .key = .{ .cp = pardes.Key.escape } }); + const nsel = pane.body.nsel; + try std.testing.expect(nsel > 0); + // Another view live: the first's share, its ranges, parked, as a + // client's is in the session a join's dump is made of. + const k = p.openView().?; + p.toView(k); + const bytes = try byteDump(p); + defer gpa.free(bytes); + const q = try load(gpa, .{ .tty_only = true, .cols = 80, .rows = 24 }, bytes, null); + defer q.deinit(); + try std.testing.expectEqual(walk.digest(Pardes, p), walk.digest(Pardes, q)); + q.toView(.at(0)); + try std.testing.expectEqual(nsel, q.panes[0].?.body.nsel); +} |
