forked from simdjson/simdjson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuzz_atpointer.cpp
47 lines (39 loc) · 1.25 KB
/
fuzz_atpointer.cpp
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
#include "FuzzUtils.h"
#include "simdjson.h"
#include <cstddef>
#include <cstdint>
#include <string>
#include <string_view>
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
// Split data into two strings, JSON Pointer and the document string.
// Might end up with none, either or both being empty, important for
// covering edge cases such as
// https://github.com/simdjson/simdjson/issues/1142 Inputs missing the
// separator line will get an empty JSON Pointer but the all the input put in
// the document string. This means test data from other fuzzers that take json
// input works for this fuzzer as well.
FuzzData fd(Data, Size);
auto strings = fd.splitIntoStrings();
while (strings.size() < 2) {
strings.emplace_back();
}
assert(strings.size() >= 2);
simdjson::dom::parser parser;
// parse without exceptions, for speed
auto res = parser.parse(strings[0]);
if (res.error())
return 0;
simdjson::dom::element root;
if (res.get(root))
return 0;
auto maybe_leaf = root.at_pointer(strings[1]);
if (maybe_leaf.error())
return 0;
simdjson::dom::element leaf;
if (maybe_leaf.get(leaf))
return 0;
std::string_view sv;
if (leaf.get_string().get(sv))
return 0;
return 0;
}