summaryrefslogtreecommitdiff
path: root/core/fuzz.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-23 23:27:56 -0300
committerGabriel Schneider <[email protected]>2026-11-23 23:32:29 -0300
commit5b4f790453c636ab10a0be2686008af7a67e0afe (patch)
tree59063fba659c0f69e8b79576532e955f20d6b1f3 /core/fuzz.zig
parent263b7d2e24f5bdad6a6a62b4a13bc74b8be68cb3 (diff)
downloadpardes-5b4f790453c636ab10a0be2686008af7a67e0afe.tar.gz
pardes-5b4f790453c636ab10a0be2686008af7a67e0afe.zip
walk: every count a byte dump or an image holds is held to the bytes it came in, and the fuzz reads the byte dump a join streams as a join does: core/fuzz.zig's dump fuzz had read two IMAGES (`dump.dumpBytes` is an image too), so the byte loader a client's join runs (`walk.Load`, before the session's digest is checked) was never fuzzed; now its two wholes are `dump.byteDump` read as a join reads it (`Road.join`: loaded, digested, let go) and the image read as a Restore or an Upgrade reads it (`Road.restore`: loaded, drawn), 4096 seeds and 1024 (seconds each). EACH SITE BELOW WAS A RUN OF IT FIRST, then the fix: the join road's seed 96, `Loader.readInt` on a same-build dump `@intCast` a byte-wide word into a narrower int (`integer does not fit`): `std.math.cast`, BadDump; the table's counts sized allocations of 240 GB (an enum's names, a u32 read): `Loader.entries`, each count held to the bytes left by the least an entry takes (a type 1, a name and value 18, a field 6); seed 456, `skip` over a damaged table where a struct is its own field recursed to a stack overflow (a segfault): `max_depth` 256 (a session's types nest about twenty); seed 1835, a same-build enum read with `@fromBackingInt` (`invalid enum value`): `std.enums.fromInt` (`enumFrom`'s rule), BadDump; the restore road's seed 672, an image's list count sized a 10 TB allocation (`Get.slice`): held to the slots the image's bytes hold; and its byte values read with no bound (`readBytesObjectAlloc(.., null)`: 12 EB asked): `walk.most` (the database's length) at each of `Get`'s reads and `Db.Read.open`'s session. Then the counts the fuzz did not reach, by the same rule and a test that fails without it (`integer overflow` in `initEmpty`'s and `skip`'s `bits + 63`): a bitset's count (`Loader.bitCount`, read and passed over; `Get`'s), a slice's count and an array's or a skip's loop held to the bytes LEFT (were the whole dump's, or none: a loop of 2^64 skips); test walk.zig "a bitset's count read back is held to the bytes left, read or passed over, in a dump and an image: never a size that overflows". OPEN, not done here: the image road past seed 1024 reaches xitdb's own reader (seed 1780: `switch on corrupt value` in xitdb `HashMap.init`, a slot's tag byte past its kinds, from `Db.Read.blobs`): a dependency's, for build/patches.zig and a report; a byte dump that loads but means nothing (a live view that is none: a Restore of an old byte-dump file draws it and panics in `Core.view`); references read back as another type (no-panic-1's `typeWord` sites, not reached in 4096 seeds)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/fuzz.zig')
-rw-r--r--core/fuzz.zig29
1 files changed, 21 insertions, 8 deletions
diff --git a/core/fuzz.zig b/core/fuzz.zig
index f324a48e..0fce6f9d 100644
--- a/core/fuzz.zig
+++ b/core/fuzz.zig
@@ -711,7 +711,12 @@ fn damage(r: Random, b: []u8, n: usize) usize {
return n;
}
-fn loadSeed(whole: []const u8, seed: u64) !void {
+/// What is done with a dump once it loads: a join's is digested (the
+/// session's digest decides before anything draws it: replica.fromDump),
+/// a Restore's or an Upgrade's image is drawn.
+const Road = enum { join, restore };
+
+fn loadSeed(whole: []const u8, road: Road, seed: u64) !void {
var prng: Random.DefaultPrng = .init(seed);
const r = prng.random();
var cap: Capped = .{ .child = testing.allocator, .one = 64 << 20, .all = 512 << 20 };
@@ -728,8 +733,13 @@ fn loadSeed(whole: []const u8, seed: u64) !void {
var notes: std.ArrayList(u8) = .empty;
defer notes.deinit(gpa);
if (pardes.dump.load(gpa, .{ .cols = 80, .rows = 24 }, b[0..n], &notes)) |q| {
- _ = q.frame_arena.reset(.retain_capacity);
- _ = q.render(q.frame_arena.allocator()) catch {};
+ switch (road) {
+ .join => _ = pardes.tape.digestOf(q),
+ .restore => {
+ _ = q.frame_arena.reset(.retain_capacity);
+ _ = q.render(q.frame_arena.allocator()) catch {};
+ },
+ }
q.deinit();
} else |err| if (seed == 0) return err;
try testing.expectEqual(@as(usize, 0), cap.refused);
@@ -739,13 +749,16 @@ 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();
- const bytes = try pardes.dump.dumpBytes(p);
+ // The byte dump a join streams, and the image a Dump keeps.
+ const bytes = try pardes.dump.byteDump(p);
defer gpa.free(bytes);
- const image = try pardes.dump.image(p, "fuzz");
+ const image = try pardes.dump.dumpBytes(p);
defer gpa.free(image);
- for ([_][]const u8{ bytes, image }) |whole| {
- try loadSeed(whole, 0);
- for (seeds) |seed| for (0..8) |k| try loadSeed(whole, seed *% 31 +% k);
+ // Seconds a road. The image's past 1024 seeds reach xitdb's own reader
+ // (a slot's tag past its kinds: a `switch` on it), a dependency's.
+ for ([_][]const u8{ bytes, image }, [_]Road{ .join, .restore }, [_]u64{ 4096, 1024 }) |whole, road, n| {
+ try loadSeed(whole, road, 0);
+ for (1..n + 1) |seed| try loadSeed(whole, road, seed);
}
}