authorgravatar for goon.pri.low@gmail.comKendall Condon <goon.pri.low@gmail.com> 2026-03-11 20:28:13-04:00
committergravatar for goon.pri.low@gmail.comKendall Condon <goon.pri.low@gmail.com> 2026-03-11 20:28:13-04:00
logcc2d992e2494f29d3d03f58a8ff318dd64815a1f
tree7ab0cc62f9ed275c29ad3d2cc4c00a2e0012fe12
parentc3a417206a6780393dae871a351fb9617012aee2

libfuzzer: make corpus inputs go through mmap


1 files changed, 13 insertions(+), 4 deletions(-)

lib/fuzzer.zig+13-4
......@@ -703,7 +703,7 @@ const Fuzzer = struct {
703703 else => panic("failed to read corpus file '{s}': {t}", .{ name, e }),
704704 };
705705 defer gpa.free(bytes);
706 f.newInput(bytes, false);
706 f.newInputExternal(bytes);
707707 }
708708 f.corpus_pos = @enumFromInt(0);
709709 }
......@@ -861,7 +861,16 @@ const Fuzzer = struct {
861861 }
862862 }
863863
864 pub fn newInput(f: *Fuzzer, bytes: []const u8, modify_fs_corpus: bool) void {
864 pub fn newInputExternal(f: *Fuzzer, bytes: []const u8) void {
865 // All inputs including the corpus are required to go through the memory
866 // mapped input in case they cause a crash so they can be identified.
867 f.mmap_input.appendSlice(bytes);
868 f.newInput(false);
869 f.mmap_input.clearRetainingCapacity();
870 }
871
872 fn newInput(f: *Fuzzer, modify_fs_corpus: bool) void {
873 const bytes = f.mmap_input.inputSlice();
865874 f.runBytes(bytes, .bytes_fresh);
866875 f.req_values = f.input_builder.total_ints + f.input_builder.total_bytes;
867876 f.req_bytes = @intCast(f.input_builder.bytes_table.items.len);
......@@ -1081,7 +1090,7 @@ const Fuzzer = struct {
10811090 @branchHint(.unlikely);
10821091
10831092 _ = @atomicRmw(usize, &exec.seenPcsHeader().unique_runs, .Add, 1, .monotonic);
1084 f.newInput(f.mmap_input.inputSlice(), true);
1093 f.newInput(true);
10851094 }
10861095 f.mmap_input.clearRetainingCapacity();
10871096
......@@ -1675,7 +1684,7 @@ export fn fuzzer_set_test(test_one: abi.TestOne, unit_test_name: abi.Slice) void
16751684
16761685export fn fuzzer_new_input(bytes: abi.Slice) void {
16771686 if (bytes.len == 0) return; // An entry of length zero is always present
1678 fuzzer.newInput(bytes.toSlice(), false);
1687 fuzzer.newInputExternal(bytes.toSlice());
16791688}
16801689
16811690export fn fuzzer_main(limit_kind: abi.LimitKind, amount: u64) void {