File: fuzz_ndjson.cpp

package info (click to toggle)
simdjson 4.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,936 kB
  • sloc: cpp: 171,612; ansic: 19,122; sh: 1,126; python: 842; makefile: 47; ruby: 25; javascript: 13
file content (33 lines) | stat: -rw-r--r-- 1,064 bytes parent folder | download | duplicates (3)
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
#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;
  simdjson::dom::document_stream docs;
  if(parser.parse_many(json,batch_size).get(docs)) { return 0; }
  size_t bool_count1 = 0;
  size_t total_count1 = 0;
  for (auto doc : docs) {
    total_count1++;
    bool_count1 += doc.is_bool();
  }
  // Restart, if we made it this far, the document *must* be accessible.
  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();
  }
  // They should agree!!!
  if((total_count2 != total_count1) || (bool_count2 != bool_count1)) { return EXIT_FAILURE; }
  return 0;
}