Skip to content

Commit 6318098

Browse files
committed
add fuzzer for ndjson
1 parent 03aaaae commit 6318098

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎fuzz/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ set(SOURCES
3131
fuzz_dump.cpp
3232
fuzz_print_json.cpp
3333
fuzz_dump_raw_tape.cpp
34+
fuzz_ndjson.cpp
3435
)
3536

3637
add_custom_target(print_all_fuzz_targets

‎fuzz/fuzz_ndjson.cpp‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include "simdjson.h"
2+
#include <cstddef>
3+
#include <cstdint>
4+
#include <string>
5+
6+
#include "NullBuffer.h"
7+
8+
9+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
10+
11+
// inspired by doc/basics.md#newline-delimited-json-ndjson-and-json-lines
12+
try {
13+
simdjson::dom::parser pj;
14+
auto docs=pj.parse_many(Data, Size);
15+
NulOStream os;
16+
for(simdjson::dom::element root: docs ) {
17+
os<<root;
18+
}
19+
} catch (...) {
20+
}
21+
return 0;
22+
}

0 commit comments

Comments
 (0)