forked from simdjson/simdjson
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzz_jsonptr.cpp
More file actions
47 lines (40 loc) · 1.17 KB
/
Copy pathfuzz_jsonptr.cpp
File metadata and controls
47 lines (40 loc) · 1.17 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
#include "simdjson.h"
#include <cstddef>
#include <cstdint>
#include <string>
#include "NullBuffer.h"
// why is this not in <algorithm>?
template<class Iterator, class Element>
Iterator find_last(Iterator first, Iterator last, const Element& e) {
Iterator ret=last;
while(first!=ret) {
--ret;
if(*ret==e) {
return ret;
}
}
return last;
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
// split the input in two, the first part will be used as json and
// the second part as index to use for the json pointer
const uint8_t sep='\t';
const uint8_t* end=Data+Size;
const uint8_t* mid = find_last(Data,end,sep);
const size_t Size1=std::distance(Data,mid);
if(Size1<Size) {
++mid;
}
const size_t Size2=std::distance(mid,end);
// inspired by doc/basics.md#json-pointer
try {
simdjson::dom::parser pj;
simdjson::dom::element root=pj.parse(Data, Size1);
auto key=std::string_view((const char*)mid,Size2);
NulOStream os;
//std::ostream& os(std::cout);
os<< root[key]<<'\n';
} catch (...) {
}
return 0;
}