Skip to content

Commit 57815e9

Browse files
committed
Fix corpus
Pass absolute paths to corpus. The corpus needs to be single files with one sample each. Add a Python script that converts files with multiple samples into single files.
1 parent 4249015 commit 57815e9

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

fuzzing/Jamfile

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,45 @@
66

77

88
import common ;
9+
import path ;
10+
import python ;
911
import regex ;
12+
import toolset ;
13+
14+
path-constant HERE : . ;
1015

1116
local all_fuzzers = [ regex.replace-list
1217
[ glob "fuzz_*.cpp" ] : ".cpp" : ""
1318
] ;
1419

20+
if ! [ python.configured ]
21+
{
22+
using python ;
23+
}
24+
25+
.make-corpus-script = $(HERE)/make-corpus.py ;
26+
27+
rule make-corpus ( target : sources + : properties * )
28+
{
29+
RUNNER on $(target) = [ path.native $(.make-corpus-script) ] ;
30+
}
31+
actions make-corpus
32+
{
33+
"$(PYTHON:E=python)" "$(RUNNER)" $(<) $(>)
34+
}
35+
toolset.flags $(__name__).make-corpus PYTHON <python.interpreter> ;
36+
1537
for local fuzzer in $(all_fuzzers)
1638
{
1739
local fuzz_time = 60 ;
40+
local corpus = /tmp/corpus/$(fuzzer) ;
41+
local min_corpus = /tmp/mincorpus/$(fuzzer) ;
42+
local seed_corpus = $(HERE)/seedcorpus/$(fuzzer) ;
43+
local seed_files = [ glob "$(seed_corpus)/*" ] ;
1844

1945
# Create the output corpus directories
20-
make /tmp/corpus/$(fuzzer) : : common.MkDir ;
21-
make /tmp/mincorpus/$(fuzzer) : : common.MkDir ;
46+
make $(corpus) : $(seed_files) : make-corpus ;
47+
make $(min_corpus) : : common.MkDir ;
2248

2349
# Build the fuzzer
2450
exe $(fuzzer)
@@ -36,19 +62,20 @@ for local fuzzer in $(all_fuzzers)
3662

3763
# Run the fuzzer for a short while
3864
run $(fuzzer)
39-
: <testing.arg>"seedcorpus/$(fuzzer) -max_total_time=$(fuzz_time)"
65+
: <testing.arg>"$(corpus) -max_total_time=$(fuzz_time)"
4066
: target-name $(fuzzer)-fuzzing
4167
: requirements
42-
<dependency>/tmp/corpus/$(fuzzer)
68+
<dependency>$(corpus)
4369
;
4470

4571
# Minimize the corpus
4672
run $(fuzzer)
47-
: <testing.arg>"/tmp/mincorpus/$(fuzzer) /tmp/corpus/$(fuzzer) -merge=1"
73+
: <testing.arg>"$(min_corpus) $(corpus) -merge=1"
4874
: target-name $(fuzzer)-minimize-corpus
4975
: requirements
5076
<dependency>$(fuzzer)-fuzzing
51-
<dependency>/tmp/corpus/$(fuzzer)
52-
<dependency>/tmp/mincorpus/$(fuzzer)
77+
<dependency>$(corpus)
78+
<dependency>$(min_corpus)
5379
;
54-
}
80+
}
81+

fuzzing/make-corpus.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/env python
2+
3+
import os
4+
import sys
5+
6+
7+
def get_samples(input_files):
8+
for file_name in input_files:
9+
if not os.path.isfile(file_name):
10+
raise RuntimeError("Not a file: " + file_name)
11+
with open(file_name, 'r') as input_file:
12+
yield from input_file
13+
14+
15+
def process_files(output_folder, input_files):
16+
if not os.path.exists(output_folder):
17+
os.makedirs(output_folder)
18+
19+
for i, sample in enumerate(get_samples(input_files)):
20+
with open(os.path.join(output_folder, str(i) + ".txt"), 'w') as output_file:
21+
output_file.write(sample)
22+
23+
24+
if __name__ == "__main__":
25+
if len(sys.argv) < 3:
26+
print("Usage: python script.py <output_folder> <input_file1> [<input_file2> ...]")
27+
sys.exit(1)
28+
29+
process_files(output_folder=sys.argv[1], input_files=sys.argv[2:])

0 commit comments

Comments
 (0)