forked from simdjson/simdjson
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzz_dump.cpp
More file actions
60 lines (55 loc) · 1.22 KB
/
fuzz_dump.cpp
File metadata and controls
60 lines (55 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "simdjson.h"
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <string>
#include "NullBuffer.h"
// from the README on the front page
void compute_dump(simdjson::ParsedJson::Iterator &pjh) {
NulOStream os;
if (pjh.is_object()) {
os << "{";
if (pjh.down()) {
pjh.print(os); // must be a string
os << ":";
pjh.next();
compute_dump(pjh); // let us recurse
while (pjh.next()) {
os << ",";
pjh.print(os);
os << ":";
pjh.next();
compute_dump(pjh); // let us recurse
}
pjh.up();
}
os << "}";
} else if (pjh.is_array()) {
os << "[";
if (pjh.down()) {
compute_dump(pjh); // let us recurse
while (pjh.next()) {
os << ",";
compute_dump(pjh); // let us recurse
}
pjh.up();
}
os << "]";
} else {
pjh.print(os); // just print the lone value
}
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
try {
auto pj = simdjson::build_parsed_json(Data, Size);
if (!pj.is_valid()) {
throw 1;
}
simdjson::ParsedJson::Iterator pjh(pj.doc);
if (pjh.is_ok()) {
compute_dump(pjh);
}
} catch (...) {
}
return 0;
}