bazel-contrib / rules_fuzzing

Bazel Starlark extensions for defining fuzz tests in Bazel projects
Apache License 2.0
87 stars 20 forks source link

Replayer ignores hidden corpus files & directories #253

Closed simonresch closed 1 month ago

simonresch commented 2 months ago

Expected Behavior

The replayer should execute all files that are passed as corpus to a cc_fuzz_test target.

Actual Behavior

Corpus files in a hidden (. prefixed directory) or hidden files are ignored by the replayer as long as the hidden directory/file lies in the bazel project root.

Steps to Reproduce the Problem

  1. Apply the following patch, which adds a corpus file in a hidden directory for the bzlmod example:
diff --git a/examples/bzlmod/.seed-corpus/foo b/examples/bzlmod/.seed-corpus/foo
new file mode 100644
index 0000000..e69de29
diff --git a/examples/bzlmod/BUILD b/examples/bzlmod/BUILD
index 7333e6c..387c268 100644
--- a/examples/bzlmod/BUILD
+++ b/examples/bzlmod/BUILD
@@ -18,6 +18,7 @@ load("@my_rules_fuzzing//fuzzing:java_defs.bzl", "java_fuzz_test")
 cc_fuzz_test(
     name = "cc_fuzz_test",
     srcs = ["cc_fuzz_test.cc"],
+    corpus = [".seed-corpus/foo"],
 )

 java_fuzz_test(
diff --git a/examples/bzlmod/cc_fuzz_test.cc b/examples/bzlmod/cc_fuzz_test.cc
index b08b002..e6a07b9 100644
--- a/examples/bzlmod/cc_fuzz_test.cc
+++ b/examples/bzlmod/cc_fuzz_test.cc
@@ -16,7 +16,9 @@

 #include <cstddef>
 #include <cstdint>
+#include <iostream>

 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+  throw std::runtime_error("Executing corpus file");
   return 0;
 }
  1. In the examples/bzlmod directory run bazel coverage //:cc_fuzz_test.

The replayer should replay the .seed-corpus/foo and trigger the inserted exception in LLVMFuzzerTestOneInput. Instead, the coverage calculation passes without executing a corpus file.

Specifications