2020-03-03 06:23:19 +08:00
|
|
|
#include "simdjson.h"
|
2019-10-29 02:46:57 +08:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
2019-12-28 02:42:44 +08:00
|
|
|
#include "NullBuffer.h"
|
2019-10-29 02:46:57 +08:00
|
|
|
|
|
|
|
// 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);
|
2020-03-14 08:43:24 +08:00
|
|
|
if (!pj.is_valid()) {
|
|
|
|
throw 1;
|
|
|
|
}
|
2020-03-26 03:03:03 +08:00
|
|
|
simdjson::ParsedJson::Iterator pjh(pj);
|
2019-10-29 02:46:57 +08:00
|
|
|
if (pjh.is_ok()) {
|
|
|
|
compute_dump(pjh);
|
|
|
|
}
|
|
|
|
} catch (...) {
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|