authorgravatar for goon.pri.low@gmail.comKendall Condon <goon.pri.low@gmail.com> 2026-03-22 18:00:51-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-23 05:19:04+01:00
log1708da2c710bd5fa84167ed4abc7ec79438c9be4
tree3d5a94eef7ab91879eb046f90c58d72398ebc485
parentb2c2b4d0630716fa6a61ec27df26c5253f2de5b0

libfuzzer: fix SkipZigTest with new inputs

It is now ignored for inputs from the corpus to ensure the filesystem and process corpus stay in sync. For other (nondeterministic) inputs the input builder is now reset.

1 files changed, 23 insertions(+), 2 deletions(-)

lib/fuzzer.zig+23-2
...@@ -594,6 +594,21 @@ const Fuzzer = struct {...@@ -594,6 +594,21 @@ const Fuzzer = struct {
594 b.smithed_len = 4;594 b.smithed_len = 4;
595 return input;595 return input;
596 }596 }
597
598 pub fn reset(b: *Builder) void {
599 const uid_slices = b.uid_slices.entries.slice();
600 for (uid_slices.items(.key), uid_slices.items(.value)) |uid, *uid_data| {
601 switch (uid.kind) {
602 .int => uid_data.ints.deinit(gpa),
603 .bytes => uid_data.bytes.deinit(gpa),
604 }
605 }
606 b.uid_slices.clearRetainingCapacity();
607 b.total_ints = 0;
608 b.total_bytes = 0;
609 b.weighted_len = 0;
610 b.smithed_len = 4;
611 }
597 };612 };
598 };613 };
599614
...@@ -876,7 +891,14 @@ const Fuzzer = struct {...@@ -876,7 +891,14 @@ const Fuzzer = struct {
876 // * The test has changed and a previous corpus input is being used891 // * The test has changed and a previous corpus input is being used
877 // * An input provided by the test results in it892 // * An input provided by the test results in it
878 // * The test is non-deterministic893 // * The test is non-deterministic
879 if (f.runBytes(bytes, .bytes_fresh)) return;894 if (f.runBytes(bytes, .bytes_fresh) and
895 modify_fs_corpus // The input is not from the filesystem.
896 // This is required to ensure the filesystem and process corpus are the same.
897 ) {
898 f.input_builder.reset();
899 f.corpus_pos = @enumFromInt(0);
900 return;
901 }
880 f.req_values = f.input_builder.total_ints + f.input_builder.total_bytes;902 f.req_values = f.input_builder.total_ints + f.input_builder.total_bytes;
881 f.req_bytes = @intCast(f.input_builder.bytes_table.items.len);903 f.req_bytes = @intCast(f.input_builder.bytes_table.items.len);
882 var input = f.input_builder.build();904 var input = f.input_builder.build();
...@@ -1859,7 +1881,6 @@ const MemoryMappedInput = struct {...@@ -1859,7 +1881,6 @@ const MemoryMappedInput = struct {
1859 /// Invalidates item pointers if more space is required.1881 /// Invalidates item pointers if more space is required.
1860 pub fn appendLittleInt(l: *MemoryMappedInput, T: type, x: T) void {1882 pub fn appendLittleInt(l: *MemoryMappedInput, T: type, x: T) void {
1861 l.ensureUnusedCapacity(@sizeOf(T));1883 l.ensureUnusedCapacity(@sizeOf(T));
1862 //std.log.debug("{} {} {}", .{ l.writeSlice().len, l.len, @sizeOf(T) });
1863 l.writeSlice()[4 + l.len ..][0..@sizeOf(T)].* = @bitCast(mem.nativeToLittle(T, x));1884 l.writeSlice()[4 + l.len ..][0..@sizeOf(T)].* = @bitCast(mem.nativeToLittle(T, x));
1864 l.len += @sizeOf(T);1885 l.len += @sizeOf(T);
1865 l.writeLen();1886 l.writeLen();