From e3a1ee1fc31c646d67b0d83874c7d3429c1cbaba Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Wed, 15 Jan 2025 08:58:02 -0500 Subject: [PATCH 1/4] Add python script for generating seed-corpus --- fuzzing/make-corpus.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 fuzzing/make-corpus.py diff --git a/fuzzing/make-corpus.py b/fuzzing/make-corpus.py new file mode 100644 index 00000000..93d6d0da --- /dev/null +++ b/fuzzing/make-corpus.py @@ -0,0 +1,32 @@ +#!/bin/env python + +# Copyright (c) 2025 Alexander Grund +# Distributed under the Boost Software License, Version 1.0. +# https://www.boost.org/LICENSE_1_0.txt. + +import os +import sys + +def get_samples(input_files): + for file_name in input_files: + if not os.path.isfile(file_name): + raise RuntimeError("Not a file: " + file_name) + with open(file_name, 'r') as input_file: + yield from input_file + + +def process_files(output_folder, input_files): + if not os.path.exists(output_folder): + os.makedirs(output_folder) + + for i, sample in enumerate(get_samples(input_files)): + with open(os.path.join(output_folder, str(i) + ".txt"), 'w') as output_file: + output_file.write(sample) + + +if __name__ == "__main__": + if len(sys.argv) < 3: + print("Usage: python script.py [ ...]") + sys.exit(1) + + process_files(output_folder=sys.argv[1], input_files=sys.argv[2:]) From a8475b991a5cdb15d8928c1a54b7933de8028778 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Wed, 15 Jan 2025 08:58:08 -0500 Subject: [PATCH 2/4] Update jamfile --- fuzzing/Jamfile | 59 +++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/fuzzing/Jamfile b/fuzzing/Jamfile index 0ddceb0c..684dc178 100644 --- a/fuzzing/Jamfile +++ b/fuzzing/Jamfile @@ -1,27 +1,52 @@ # # Copyright (c) 2019-2023 Ruben Perez Hidalgo (rubenperez038 at gmail dot com) # Copyright (c) 2024 Matt Borland +# Copyright (c) 2025 Alexander Grund # -# Distributed under the Boost Software License, Version 1.0. (See accompanying -# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +# Distributed under the Boost Software License, Version 1.0. +# https://www.boost.org/LICENSE_1_0.txt. # import common ; +import path ; +import python ; import regex ; +import toolset ; + +path-constant HERE : . ; local all_fuzzers = [ regex.replace-list [ glob "fuzz_*.cpp" ] : ".cpp" : "" ] ; +if ! [ python.configured ] +{ + using python ; +} + +.make-corpus-script = $(HERE)/make-corpus.py ; + +rule make-corpus ( target : sources + : properties * ) +{ + RUNNER on $(target) = [ path.native $(.make-corpus-script) ] ; +} +actions make-corpus +{ + "$(PYTHON:E=python)" "$(RUNNER)" $(<) $(>) +} +toolset.flags $(__name__).make-corpus PYTHON ; + for local fuzzer in $(all_fuzzers) { - # These two fuzzers are the most complex ones. The rest are really - # simple, so less time is enough - local fuzz_time = 30 ; + local fuzz_time = 60 ; + local corpus = /tmp/corpus/$(fuzzer) ; + local min_corpus = /tmp/mincorpus/$(fuzzer) ; + local seed_corpus = $(HERE)/seedcorpus/$(fuzzer) ; + local seed_files = [ glob "$(seed_corpus)/*" ] ; # Create the output corpus directories - make /tmp/corpus/$(fuzzer) : : common.MkDir ; - make /tmp/mincorpus/$(fuzzer) : : common.MkDir ; + make $(corpus) : $(seed_files) : make-corpus ; + make $(min_corpus) : : common.MkDir ; # Build the fuzzer exe $(fuzzer) @@ -37,31 +62,21 @@ for local fuzzer in $(all_fuzzers) /boost/charconv//boost_charconv ; - # Make sure that any old crashes are run without problems - local old_crashes = [ glob-tree-ex old_crashes/$(fuzzer) : * ] ; - if $(old_crashes) - { - run $(fuzzer) - : target-name $(fuzzer)-old-crashes - : input-files [ SORT $(old_crashes) ] - ; - } - # Run the fuzzer for a short while run $(fuzzer) - : "seedcorpus/$(fuzzer) -max_total_time=$(fuzz_time)" + : "$(corpus) -max_total_time=$(fuzz_time)" : target-name $(fuzzer)-fuzzing : requirements - /tmp/corpus/$(fuzzer) + $(corpus) ; # Minimize the corpus run $(fuzzer) - : "/tmp/mincorpus/$(fuzzer) /tmp/corpus/$(fuzzer) -merge=1" + : "$(min_corpus) $(corpus) -merge=1" : target-name $(fuzzer)-minimize-corpus : requirements $(fuzzer)-fuzzing - /tmp/corpus/$(fuzzer) - /tmp/mincorpus/$(fuzzer) + $(corpus) + $(min_corpus) ; } From f62e9f92193c1c22180d30cceb14f745eb87f662 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Wed, 15 Jan 2025 11:13:41 -0500 Subject: [PATCH 3/4] Apply suggestions from grafikbot review, and revert run duration --- fuzzing/Jamfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fuzzing/Jamfile b/fuzzing/Jamfile index 684dc178..3e10a7c2 100644 --- a/fuzzing/Jamfile +++ b/fuzzing/Jamfile @@ -32,20 +32,20 @@ rule make-corpus ( target : sources + : properties * ) } actions make-corpus { - "$(PYTHON:E=python)" "$(RUNNER)" $(<) $(>) + "$(PYTHON:E=python)" "$(RUNNER)" "$(<)" "$(>)" } toolset.flags $(__name__).make-corpus PYTHON ; for local fuzzer in $(all_fuzzers) { - local fuzz_time = 60 ; + local fuzz_time = 30 ; local corpus = /tmp/corpus/$(fuzzer) ; local min_corpus = /tmp/mincorpus/$(fuzzer) ; local seed_corpus = $(HERE)/seedcorpus/$(fuzzer) ; local seed_files = [ glob "$(seed_corpus)/*" ] ; # Create the output corpus directories - make $(corpus) : $(seed_files) : make-corpus ; + make $(corpus) : $(seed_files) : make-corpus : $(.make-corpus-script) ; make $(min_corpus) : : common.MkDir ; # Build the fuzzer From 9ac6e5776fab1e33eab103b146385c3d058cae1e Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Wed, 15 Jan 2025 14:30:24 -0500 Subject: [PATCH 4/4] Remove space in dependency line --- fuzzing/Jamfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fuzzing/Jamfile b/fuzzing/Jamfile index 3e10a7c2..0b12c16e 100644 --- a/fuzzing/Jamfile +++ b/fuzzing/Jamfile @@ -45,7 +45,7 @@ for local fuzzer in $(all_fuzzers) local seed_files = [ glob "$(seed_corpus)/*" ] ; # Create the output corpus directories - make $(corpus) : $(seed_files) : make-corpus : $(.make-corpus-script) ; + make $(corpus) : $(seed_files) : make-corpus : $(.make-corpus-script) ; make $(min_corpus) : : common.MkDir ; # Build the fuzzer