Additional ndjson tests. (#1717)
* Additional ndjson tests. * Switching the data source. * Fixing.
This commit is contained in:
parent
4e609aa955
commit
cae5e5342f
|
@ -8,24 +8,26 @@
|
||||||
|
|
||||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
||||||
FuzzData fd(Data, Size);
|
FuzzData fd(Data, Size);
|
||||||
const auto batch_size=static_cast<size_t>(fd.getInt<0,1000>());
|
const auto batch_size = static_cast<size_t>(fd.getInt<0,1000>());
|
||||||
const auto json=simdjson::padded_string{fd.remainder_as_stringview()};
|
const auto json = simdjson::padded_string{fd.remainder_as_stringview()};
|
||||||
simdjson::dom::parser parser;
|
simdjson::dom::parser parser;
|
||||||
#if SIMDJSON_EXCEPTIONS
|
simdjson::dom::document_stream docs;
|
||||||
try {
|
if(parser.parse_many(json,batch_size).get(docs)) { return 0; }
|
||||||
#endif
|
size_t bool_count1 = 0;
|
||||||
simdjson::dom::document_stream docs;
|
size_t total_count1 = 0;
|
||||||
if(parser.parse_many(json,batch_size).get(docs)) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[maybe_unused]] size_t bool_count=0;
|
|
||||||
for (auto doc : docs) {
|
for (auto doc : docs) {
|
||||||
bool_count+=doc.is_bool();
|
total_count1++;
|
||||||
|
bool_count1 += doc.is_bool();
|
||||||
}
|
}
|
||||||
#if SIMDJSON_EXCEPTIONS
|
// Restart, if we made it this far, the document *must* be accessible.
|
||||||
} catch(...) {
|
if(parser.parse_many(json,batch_size).get(docs)) { return EXIT_FAILURE; }
|
||||||
|
size_t bool_count2 = 0;
|
||||||
|
size_t total_count2 = 0;
|
||||||
|
for (auto doc : docs) {
|
||||||
|
total_count2++;
|
||||||
|
bool_count2 += doc.is_bool();
|
||||||
}
|
}
|
||||||
#endif
|
// They should agree!!!
|
||||||
|
if((total_count2 != total_count1) || (bool_count2 != bool_count1)) { return EXIT_FAILURE; }
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -861,6 +861,23 @@ namespace document_stream_tests {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool fuzzaccess() {
|
||||||
|
std::cout << "Running " << __func__ << std::endl;
|
||||||
|
// Issue 38801 in oss-fuzz
|
||||||
|
auto json = "\xff \n~~\n{}"_padded;
|
||||||
|
simdjson::dom::parser parser;
|
||||||
|
simdjson::dom::document_stream docs;
|
||||||
|
ASSERT_SUCCESS(parser.parse_many(json).get(docs));
|
||||||
|
size_t bool_count = 0;
|
||||||
|
size_t total_count = 0;
|
||||||
|
|
||||||
|
for (auto doc : docs) {
|
||||||
|
total_count++;
|
||||||
|
bool_count += doc.is_bool();
|
||||||
|
}
|
||||||
|
return (bool_count == 0) && (bool_count == 0);
|
||||||
|
}
|
||||||
|
|
||||||
bool baby_fuzzer() {
|
bool baby_fuzzer() {
|
||||||
std::cout << "Running " << __func__ << std::endl;
|
std::cout << "Running " << __func__ << std::endl;
|
||||||
std::mt19937 gen(637);
|
std::mt19937 gen(637);
|
||||||
|
@ -892,7 +909,8 @@ namespace document_stream_tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool run() {
|
bool run() {
|
||||||
return baby_fuzzer() &&
|
return fuzzaccess() &&
|
||||||
|
baby_fuzzer() &&
|
||||||
issue1649() &&
|
issue1649() &&
|
||||||
adversarial_single_document_array() &&
|
adversarial_single_document_array() &&
|
||||||
adversarial_single_document() &&
|
adversarial_single_document() &&
|
||||||
|
|
|
@ -511,6 +511,23 @@ namespace document_stream_tests {
|
||||||
TEST_SUCCEED();
|
TEST_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool fuzzaccess() {
|
||||||
|
TEST_START();
|
||||||
|
// Issue 38801 in oss-fuzz
|
||||||
|
auto json = "\xff \n~~\n{}"_padded;
|
||||||
|
ondemand::parser parser;
|
||||||
|
ondemand::document_stream docs;
|
||||||
|
ASSERT_SUCCESS(parser.iterate_many(json).get(docs));
|
||||||
|
size_t bool_count = 0;
|
||||||
|
size_t total_count = 0;
|
||||||
|
for (auto doc : docs) {
|
||||||
|
total_count++;
|
||||||
|
bool b;
|
||||||
|
if(doc.get_bool().get(b) == SUCCESS) { bool_count +=b; }
|
||||||
|
}
|
||||||
|
return (bool_count == 0) && (bool_count == 0);
|
||||||
|
}
|
||||||
|
|
||||||
bool run() {
|
bool run() {
|
||||||
return
|
return
|
||||||
issue1683() &&
|
issue1683() &&
|
||||||
|
|
Loading…
Reference in New Issue