summaryrefslogtreecommitdiff
path: root/core/dump.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-24 22:32:26 -0300
committerGabriel Schneider <[email protected]>2026-11-24 22:32:26 -0300
commit26b52707c97b98f650a3402654d27b4a62eed8f8 (patch)
treeec615c0fe078015024255b219fb1aa7bd51162ea /core/dump.zig
parent8c083912002f5cfdf268ed45ec217fbd8bde41d0 (diff)
downloadpardes-26b52707c97b98f650a3402654d27b4a62eed8f8.tar.gz
pardes-26b52707c97b98f650a3402654d27b4a62eed8f8.zip
dump: a load frees what it read after the core as the things it made, once each (item 5 of A2, on line A2; the fix B made in ozlumvqo, the same hunks): the 40,000-seed dump fuzz on xqqlroux panicked at join seed 19224 with `double free` (the first free dump.zig:422 `defer gpa.free(theme)` in loadKnowing, the second the errdefer's rollback, the slice allocated by walk.zig slice:1847 inside the core's own fields); THE CAUSE: walk.Load.ref hands back a slice made before (the load's `shared` list), which for a damaged dump's theme read after the core is one the loaded core holds, and loadKnowing freed its trailing reads (mounts, theme, the other views' shares) by hand: a reference freed once by the defer and again by the rollback of a later failed read; THE FIX (B's, ozlumvqo, verbatim, so the merge coincides): one defer frees `l.shared.items[read..]` (what the load made after the core) and drops it from the rollback, the views' shares the same; a user could hit it only with a damaged or hostile dump (a join's stream, a Restore file); TEST FIRST: fuzz.zig's session now holds a view in Help (`SPC t w` remembered, `SPC ? hel`: View.tag_state out of rest in every dump it cuts) and checks join seed 19224 by name (fails before: double free); the fuzz at 40,000 join and 1,779 image seeds green (core-test filter, 2 min, 8 of 8)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'core/dump.zig')
-rw-r--r--core/dump.zig19
1 files changed, 9 insertions, 10 deletions
diff --git a/core/dump.zig b/core/dump.zig
index 49b2605a..4bb89dae 100644
--- a/core/dump.zig
+++ b/core/dump.zig
@@ -406,20 +406,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;
@@ -453,8 +452,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();