fuzz more of generic/numberparsing.h (#1272)

make the ondemand fuzzer use more of the api
This commit is contained in:
Paul Dreik 2020-11-01 06:29:16 +01:00 committed by GitHub
parent 500e4c3572
commit b7fe764e6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 50 additions and 25 deletions

View File

@ -1,32 +1,17 @@
#include "FuzzUtils.h"
#include "simdjson.h"
#include <cstddef>
#include <cstdint>
#include <string>
std::vector<std::string_view> split(const char *Data, size_t Size) {
std::vector<std::string_view> ret;
using namespace std::literals;
constexpr auto sep="\n~~\n"sv;
std::string_view all(Data,Size);
auto pos=all.find(sep);
while(pos!=std::string_view::npos) {
ret.push_back(all.substr(0,pos));
all=all.substr(pos+sep.size());
pos=all.find(sep);
}
ret.push_back(all);
return ret;
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
FuzzData fd(Data, Size);
const int action = fd.getInt<0, 12>();
std::vector<std::string_view> strings=split(static_cast<const char*>(static_cast<const void*>(Data)),Size);
if(strings.size()<2) {
return 0;
// split the remainder of the document into strings
auto strings = fd.splitIntoStrings();
while (strings.size() < 1) {
strings.emplace_back();
}
#if SIMDJSON_EXCEPTIONS
try {
@ -34,11 +19,51 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
simdjson::builtin::ondemand::parser parser;
simdjson::padded_string padded(strings[0]);
auto doc = parser.iterate(padded);
if(doc.error()) {
if (doc.error()) {
return 0;
}
for (auto item : doc/*[strings[1]]*/) {
simdjson_unused auto str=item.get_string();
for (auto item : doc) {
switch (action) {
case 0: {
simdjson_unused auto x = item.get_string();
} break;
case 1: {
simdjson_unused auto x = item.get_bool();
} break;
case 2: {
simdjson_unused auto x = item.get_array();
} break;
case 3: {
simdjson_unused auto x = item.get_int64();
} break;
case 4: {
simdjson_unused auto x = item.get_double();
} break;
case 5: {
simdjson_unused auto x = item.get_object();
} break;
case 6: {
simdjson_unused auto x = item.get_uint64();
} break;
case 7: {
simdjson_unused auto x = item.get_raw_json_string();
} break;
case 8: {
simdjson_unused auto x = item.is_null();
} break;
case 9: {
simdjson_unused auto x = item.begin();
} break;
case 10: {
simdjson_unused auto x = item.end();
} break;
case 11: {
for (auto e : item) {
simdjson_unused auto x = e.is_null();
}
} break;
default:;
}
}
#if SIMDJSON_EXCEPTIONS
} catch (...) {