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 {...@@ -703,7 +703,7 @@ const Fuzzer = struct {
703 else => panic("failed to read corpus file '{s}': {t}", .{ name, e }),703 else => panic("failed to read corpus file '{s}': {t}", .{ name, e }),
704 };704 };
705 defer gpa.free(bytes);705 defer gpa.free(bytes);
706 f.newInput(bytes, false);706 f.newInputExternal(bytes);
707 }707 }
708 f.corpus_pos = @enumFromInt(0);708 f.corpus_pos = @enumFromInt(0);
709 }709 }
...@@ -861,7 +861,16 @@ const Fuzzer = struct {...@@ -861,7 +861,16 @@ const Fuzzer = struct {
861 }861 }
862 }862 }
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();
865 f.runBytes(bytes, .bytes_fresh);874 f.runBytes(bytes, .bytes_fresh);
866 f.req_values = f.input_builder.total_ints + f.input_builder.total_bytes;875 f.req_values = f.input_builder.total_ints + f.input_builder.total_bytes;
867 f.req_bytes = @intCast(f.input_builder.bytes_table.items.len);876 f.req_bytes = @intCast(f.input_builder.bytes_table.items.len);
...@@ -1081,7 +1090,7 @@ const Fuzzer = struct {...@@ -1081,7 +1090,7 @@ const Fuzzer = struct {
1081 @branchHint(.unlikely);1090 @branchHint(.unlikely);
10821091
1083 _ = @atomicRmw(usize, &exec.seenPcsHeader().unique_runs, .Add, 1, .monotonic);1092 _ = @atomicRmw(usize, &exec.seenPcsHeader().unique_runs, .Add, 1, .monotonic);
1084 f.newInput(f.mmap_input.inputSlice(), true);1093 f.newInput(true);
1085 }1094 }
1086 f.mmap_input.clearRetainingCapacity();1095 f.mmap_input.clearRetainingCapacity();
10871096
...@@ -1675,7 +1684,7 @@ export fn fuzzer_set_test(test_one: abi.TestOne, unit_test_name: abi.Slice) void...@@ -1675,7 +1684,7 @@ export fn fuzzer_set_test(test_one: abi.TestOne, unit_test_name: abi.Slice) void
16751684
1676export fn fuzzer_new_input(bytes: abi.Slice) void {1685export fn fuzzer_new_input(bytes: abi.Slice) void {
1677 if (bytes.len == 0) return; // An entry of length zero is always present1686 if (bytes.len == 0) return; // An entry of length zero is always present
1678 fuzzer.newInput(bytes.toSlice(), false);1687 fuzzer.newInputExternal(bytes.toSlice());
1679}1688}
16801689
1681export fn fuzzer_main(limit_kind: abi.LimitKind, amount: u64) void {1690export fn fuzzer_main(limit_kind: abi.LimitKind, amount: u64) void {