Skip to content

Commit fa637fc

Browse files
authored
Enable the minifier fuzzer (fixes simdjson#530) (simdjson#694)
This enables the minify fuzzer, which has been disabled because it did not pass the oss-fuzz instrumentation test. Now it does, after changes in simdjson (simdjson#186). * get minify running (api change) * disable benchmarks when compiling fuzzers * catch exceptions from the minify fuzzer * enable repeated corpus creation without recursive inclusion of zip * remove leftover comment
1 parent 4af7d6f commit fa637fc

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

fuzz/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ set(SIMDJSON_FUZZ_LDFLAGS "" CACHE STRING "LDFLAGS for the fuzz targets")
2727

2828
set(SOURCES
2929
fuzz_parser.cpp
30-
# fuzz_minify.cpp # <--- does not pass the build check test on oss-fuzz, says "partially instrumented". help needed!
30+
fuzz_minify.cpp
3131
fuzz_dump.cpp
3232
fuzz_print_json.cpp
3333
fuzz_dump_raw_tape.cpp

fuzz/fuzz_minify.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44
#include <string>
55
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
66

7-
auto begin = (const char *)Data;
8-
auto end = begin + Size;
7+
auto begin = (const char *)Data;
8+
auto end = begin + Size;
99

10-
std::string str(begin, end);
10+
std::string str(begin, end);
1111

12-
simdjson::json_minify(str.data(), str.size(), str.data());
13-
return 0;
12+
try {
13+
simdjson::dom::parser parser;
14+
simdjson::dom::element doc = parser.parse(str);
15+
std::string minified=simdjson::minify(doc);
16+
(void)minified;
17+
} catch (...) {
18+
19+
}
20+
return 0;
1421
}

fuzz/ossfuzz.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ cmake .. \
3030
-DCMAKE_BUILD_TYPE=Debug \
3131
-DSIMDJSON_BUILD_STATIC=On \
3232
-DENABLE_FUZZING=On \
33+
-DSIMDJSON_COMPETITION=Off \
3334
-DSIMDJSON_FUZZ_LINKMAIN=Off \
3435
-DSIMDJSON_FUZZ_LDFLAGS=$LIB_FUZZING_ENGINE
3536

@@ -38,6 +39,6 @@ cmake --build .
3839
cp fuzz/fuzz_* $OUT
3940

4041
# all corpora are equal, they all take json as input
41-
for f in $OUT/fuzz* ; do
42+
for f in $(ls $OUT/fuzz* |grep -v '.zip$') ; do
4243
cp ../corpus.zip $OUT/$(basename $f).zip
4344
done

0 commit comments

Comments
 (0)