mirror of
https://github.com/simdjson/simdjson
synced 2026-06-08 17:27:07 +00:00
725ca010e7
* add ndjson fuzzer * reproduce #1310 in the newly added unit test Had to replace the input, because: 1) the fuzzer uses the first part of the input to determine the batch_size to use, so that has to be cut off 2) the master now protects against low values of batch_size I also made the test not return early, so the error is triggered.
32 lines
707 B
C++
32 lines
707 B
C++
#include "simdjson.h"
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <string>
|
|
|
|
#include "FuzzUtils.h"
|
|
#include "NullBuffer.h"
|
|
|
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
|
FuzzData fd(Data, Size);
|
|
const auto batch_size=static_cast<size_t>(fd.getInt<0,1000>());
|
|
const auto json=simdjson::padded_string{fd.remainder_as_stringview()};
|
|
simdjson::dom::parser parser;
|
|
#if SIMDJSON_EXCEPTIONS
|
|
try {
|
|
#endif
|
|
simdjson::dom::document_stream docs;
|
|
if(parser.parse_many(json,batch_size).get(docs)) {
|
|
return 0;
|
|
}
|
|
|
|
size_t bool_count=0;
|
|
for (auto doc : docs) {
|
|
bool_count+=doc.is_bool();
|
|
}
|
|
#if SIMDJSON_EXCEPTIONS
|
|
} catch(...) {
|
|
}
|
|
#endif
|
|
return 0;
|
|
}
|