Skip to content

Commit b28ab39

Browse files
authored
Fix determinism of ClusterFuzz fuzz handler (#7788)
The first time the Clusterfuzz handler runs, it does a lot of setup work that can be annoying when trying to run the fuzzer briefly to smoke out very obvious problems. To avoid that annoyance, we do not run the Clusterfuzz handler until we have already fuzzed for at least 30 seconds. However, we used to control this in the `can_run_on_wasm` method, which caused reproducibility issues because the number of calls to `random` functions would differ before and after that 30-second cutoff. Specifically, `relevant_handlers` would have a different size before and after that cutoff, so the number of `random` calls to compute `filtered_handlers` would be different. To avoid these reproducibility problems, simply return early from the `handle` method of the Clusterfuzz handler if it has not yet been 30 seconds.
1 parent 9f93631 commit b28ab39

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

scripts/fuzz_opt.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,8 +1629,20 @@ class ClusterFuzz(TestCaseHandler):
16291629
# for each iteration (once for each of the wasm files we ignore), which is
16301630
# confusing.
16311631
def handle_pair(self, input, before_wasm, after_wasm, opts):
1632+
# Do not run ClusterFuzz in the first seconds of fuzzing: the first time
1633+
# it runs is very slow (to build the bundle), which is annoying when you
1634+
# are just starting the fuzzer and looking for any obvious problems.
1635+
# Check this here as opposed to in e.g. can_run_on_wasm to avoid
1636+
# changing the observed sequence of random numbers before and after this
1637+
# threshold, which could interfere with bug reproduction.
1638+
seconds = 30
1639+
if time.time() - start_time < seconds:
1640+
return
1641+
16321642
self.ensure()
16331643

1644+
# NO RANDOM DATA SHOULD BE USED BELOW THIS POINT
1645+
16341646
# run.py() should emit these two files. Delete them to make sure they
16351647
# are created by run.py() in the next step.
16361648
fuzz_file = 'fuzz-binaryen-1.js'
@@ -1711,13 +1723,6 @@ def ensure(self):
17111723
tar.extractall(path=self.clusterfuzz_dir)
17121724
tar.close()
17131725

1714-
def can_run_on_wasm(self, wasm):
1715-
# Do not run ClusterFuzz in the first seconds of fuzzing: the first time
1716-
# it runs is very slow (to build the bundle), which is annoying when you
1717-
# are just starting the fuzzer and looking for any obvious problems.
1718-
seconds = 30
1719-
return time.time() - start_time > seconds
1720-
17211726

17221727
# Tests linking two wasm files at runtime, and that optimizations do not break
17231728
# anything. This is similar to Split(), but rather than split a wasm file into

0 commit comments

Comments
 (0)