From c3a417206a6780393dae871a351fb9617012aee2 Mon Sep 17 00:00:00 2001 From: Kendall Condon Date: Wed, 11 Mar 2026 20:23:23 -0400 Subject: [PATCH] libfuzzer: check weights for bytes mutations --- lib/fuzzer.zig | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/fuzzer.zig b/lib/fuzzer.zig index c97aeea4e8..d900bed11e 100644 --- a/lib/fuzzer.zig +++ b/lib/fuzzer.zig @@ -1320,13 +1320,23 @@ const Fuzzer = struct { if (opts.copy != 0) { if (opts.fresh == 0 or slice_i == data_slice.len) return .fresh; - return .{ .mutate = switch (uid.kind) { - .int => .{ .int = data.ints[data_i] }, - .bytes => .{ .bytes = b: { + switch (uid.kind) { + .int => { + const int = data.ints[data_i]; + if (weightsContain(int, weights)) { + @branchHint(.likely); + return .{ .mutate = .{ .int = int } }; + } + }, + .bytes => { const entry = data.bytes.entries[data_i]; - break :b data.bytes.table[entry.off..][0..entry.len]; - } }, - } }; + const bytes = data.bytes.table[entry.off..][0..entry.len]; + if (weightsContainBytes(bytes, weights)) { + @branchHint(.likely); + return .{ .mutate = .{ .bytes = bytes } }; + } + }, + } } if (!opts.splice) {