From e806f3b7346e37315c8e6698b13a18659a767e18 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Wed, 10 Jun 2020 18:53:11 +0200 Subject: [PATCH] Move the coprus initialization out of a hot path This initial corpus seeding can be done in the constructor, instead of checking if it has been initialized every single time the fuzzer generates an input. --- pythonfuzz/corpus.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pythonfuzz/corpus.py b/pythonfuzz/corpus.py index bde80c6..75e3f58 100644 --- a/pythonfuzz/corpus.py +++ b/pythonfuzz/corpus.py @@ -412,6 +412,7 @@ def __init__(self, dirs=None, max_input_size=4096, mutators_filter=None, dict_pa self._seed_run_finished = not self._inputs self._seed_idx = 0 self._save_corpus = dirs and os.path.isdir(dirs[0]) + self._inputs.append(bytearray(0)) # Work out what we'll filter filters = mutators_filter.split(' ') if mutators_filter else [] @@ -488,13 +489,8 @@ def generate_input(self): self._seed_run_finished = True return next_input - if len(self._inputs) == 0: - zero_test_case = bytearray(0) - self.put(zero_test_case) - return zero_test_case - else: - buf = self._inputs[self._rand(len(self._inputs))] - return self.mutate(buf) + buf = self._inputs[self._rand(len(self._inputs))] + return self.mutate(buf) def mutate(self, buf): res = buf[:]