diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-24 20:39:14 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-24 20:39:14 -0300 |
| commit | e6269fc4f53e0088b77ea5244ee34f5a39867268 (patch) | |
| tree | ad85417d59f6c2062869f9b828dd3e322daa89c6 | |
| parent | cfe32e52db251f3102fd724fc1121d2e7819d0fd (diff) | |
| download | pardes-e6269fc4f53e0088b77ea5244ee34f5a39867268.tar.gz pardes-e6269fc4f53e0088b77ea5244ee34f5a39867268.zip | |
dump: a load frees what it read after the core (its mounts, its theme, the other views' shares) as the things it made, once each, never by hand: a damaged dump whose theme is a reference to a slice the loaded core holds had it freed by `defer gpa.free(theme)` and again by the rollback when a later read failed (and, had the load gone on, the core keeping a freed slice); found by the 40,000-seed fuzz this line's dump layout asks for: RUN FIRST: fuzz.zig "a dump and an image cut ..." at 40,000 join seeds over a session with a reader's walk in it, join seed 19224: `panic: double free` (the first free dump.zig:421 `defer gpa.free(theme)`, the second the errdefer's `l.rollback()`, dump.zig:401); THE CAUSE: walk.Load.ref hands back a slice made before (`shared`), which for the trailing reads is the core's, and loadKnowing freed those reads by hand; THE FIX: one defer frees `l.shared.items[read..]` (what was made after the core) and drops it from the rollback, the views' shares the same; no user could hit it but with a damaged or hostile dump (a join's stream, a Restore file); TEST FIRST: the fuzz's session keeps a reader's walk and checks join seed 19224 by name (fails before: double free); the fuzz at 40,000 join and 1,779 image seeds green in 145 s
Co-Authored-By: Claude Opus 5.5 <[email protected]>
| -rw-r--r-- | core/dump.zig | 19 | ||||
| -rw-r--r-- | core/fuzz.zig | 5 |
2 files changed, 14 insertions, 10 deletions
diff --git a/core/dump.zig b/core/dump.zig index b4561ae2..683f043a 100644 --- a/core/dump.zig +++ b/core/dump.zig @@ -405,20 +405,19 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: l.allocs = .{ .image = p.image_gpa, .terminal = terminal_gpa }; try l.into(Pardes, p); const read = l.shared.items.len; - const mounts = try l.get([]const filesystem.Mount); + // What is read after the core (its mounts, its theme) is freed here, + // what the load made for it once each, and no rollback of it: a + // damaged dump's reference to a slice the core holds is the core's, + // never freed here (a theme that was one was freed by hand and again + // by the rollback). defer { - for (mounts) |m| { - gpa.free(m.name); - gpa.free(m.dial); - } - gpa.free(mounts); - // Freed here: no rollback of them. + for (l.shared.items[read..]) |m| if (m.bytes.len > 0) m.gpa.rawFree(m.bytes, m.alignment, @returnAddress()); l.shared.shrinkRetainingCapacity(read); } + const mounts = try l.get([]const filesystem.Mount); const was = try l.get(OnDisk); if (on_disk) |out| out.* = was; const theme = try l.get([]const u8); - defer gpa.free(theme); // This build's place for that theme; one it has not, its first. p.settings.theme = for (colors.themes, 0..) |t, i| { if (std.mem.eql(u8, t.name, theme)) break i; @@ -452,8 +451,8 @@ fn loadKnowing(gpa: std.mem.Allocator, opts: Options, bytes: []const u8, notes: else => return err, }; views.undumped(p, others); - for (others) |o| gpa.free(o.panes); - gpa.free(others); + // What it made, as the mounts' (above). + 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); p.readSessionFacts(); diff --git a/core/fuzz.zig b/core/fuzz.zig index 616636ab..c68c7810 100644 --- a/core/fuzz.zig +++ b/core/fuzz.zig @@ -777,6 +777,8 @@ test "a dump and an image cut, flipped and grown: refused or loaded, never a pan const gpa = testing.allocator; const p = try th.withFile(gpa, "alpha beta\ngamma\n\tdelta \xe6\x97\xa5\n"); defer p.deinit(); + // A reader's walk in it: a union, a fixed array held to its length. + p.panes[0].?.trail = pardes.Trail.reader(7, "/x/rank.zig", .{ .line = 3, .col = 2 }); // The byte dump a join streams, and the image a Dump keeps. const bytes = try pardes.dump.byteDump(p); defer gpa.free(bytes); @@ -785,6 +787,9 @@ test "a dump and an image cut, flipped and grown: refused or loaded, never a pan // Seconds a road, each core used (`use`). The image's past 1779 seeds // reach xitdb's own reader (a slot's tag past its kinds: a `switch` on // it), a dependency's. + // Join seed 19224: the theme read after the core a reference to a + // slice the core holds, freed by hand and again by the rollback. + try loadSeed(bytes, .join, 19224); for ([_][]const u8{ bytes, image }, [_]Road{ .join, .restore }, [_]u64{ 2048, 1024 }) |whole, road, n| { try loadSeed(whole, road, 0); for (1..n + 1) |seed| try loadSeed(whole, road, seed); |
