File: fuzz_atpointer.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 (47 lines) | stat: -rw-r--r-- 1,276 bytes parent folder | download | duplicates (2)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "FuzzUtils.h"
#include "simdjson.h"
#include <cstddef>
#include <cstdint>
#include <string>
#include <string_view>

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {

  // Split data into two strings, JSON Pointer and the document string.
  // Might end up with none, either or both being empty, important for
  // covering edge cases such as
  // https://github.com/simdjson/simdjson/issues/1142 Inputs missing the
  // separator line will get an empty JSON Pointer but the all the input put in
  // the document string. This means test data from other fuzzers that take json
  // input works for this fuzzer as well.
  FuzzData fd(Data, Size);
  auto strings = fd.splitIntoStrings();
  while (strings.size() < 2) {
    strings.emplace_back();
  }
  assert(strings.size() >= 2);

  simdjson::dom::parser parser;

  // parse without exceptions, for speed
  auto res = parser.parse(strings[0]);
  if (res.error())
    return 0;

  simdjson::dom::element root;
  if (res.get(root))
    return 0;

  auto maybe_leaf = root.at_pointer(strings[1]);
  if (maybe_leaf.error())
    return 0;

  simdjson::dom::element leaf;
  if (maybe_leaf.get(leaf))
    return 0;

  std::string_view sv;
  if (leaf.get_string().get(sv))
    return 0;
  return 0;
}