/src/simdjson/fuzz/fuzz_element.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | #include "simdjson.h" |
2 | | #include <cstddef> |
3 | | #include <cstdint> |
4 | | #include <string> |
5 | | |
6 | | #include "FuzzUtils.h" |
7 | | #include "NullBuffer.h" |
8 | | |
9 | 10.7k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
10 | 10.7k | FuzzData fd(Data, Size); |
11 | 10.7k | const int action = fd.getInt<0, 31>(); |
12 | | |
13 | | // there will be some templatized functions like is() which need to be tested |
14 | | // on a type. select one dynamically and create a function that will invoke |
15 | | // with that type |
16 | 10.7k | const int selecttype=fd.getInt<0,7>(); |
17 | 10.7k | auto invoke_with_type=[selecttype](auto cb) { |
18 | 876 | using constcharstar=const char*; |
19 | 876 | switch(selecttype) { |
20 | 187 | case 0: cb(bool{});break; |
21 | 122 | case 1: cb(double{});break; |
22 | 228 | case 2: cb(uint64_t{});break; |
23 | 183 | case 3: cb(int64_t{});break; |
24 | 34 | case 4: cb(std::string_view{});break; |
25 | 26 | case 5: cb(constcharstar{});break; |
26 | 55 | case 6: cb(simdjson::dom::array{});break; |
27 | 41 | case 7: cb(simdjson::dom::object{});break; |
28 | 876 | } |
29 | 876 | }; fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_1::operator()<LLVMFuzzerTestOneInput::$_0>(LLVMFuzzerTestOneInput::$_0) const Line | Count | Source | 17 | 126 | auto invoke_with_type=[selecttype](auto cb) { | 18 | 126 | using constcharstar=const char*; | 19 | 126 | switch(selecttype) { | 20 | 64 | case 0: cb(bool{});break; | 21 | 17 | case 1: cb(double{});break; | 22 | 7 | case 2: cb(uint64_t{});break; | 23 | 3 | case 3: cb(int64_t{});break; | 24 | 12 | case 4: cb(std::string_view{});break; | 25 | 3 | case 5: cb(constcharstar{});break; | 26 | 18 | case 6: cb(simdjson::dom::array{});break; | 27 | 2 | case 7: cb(simdjson::dom::object{});break; | 28 | 126 | } | 29 | 126 | }; |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_1::operator()<LLVMFuzzerTestOneInput::$_2>(LLVMFuzzerTestOneInput::$_2) const Line | Count | Source | 17 | 58 | auto invoke_with_type=[selecttype](auto cb) { | 18 | 58 | using constcharstar=const char*; | 19 | 58 | switch(selecttype) { | 20 | 13 | case 0: cb(bool{});break; | 21 | 18 | case 1: cb(double{});break; | 22 | 11 | case 2: cb(uint64_t{});break; | 23 | 3 | case 3: cb(int64_t{});break; | 24 | 1 | case 4: cb(std::string_view{});break; | 25 | 2 | case 5: cb(constcharstar{});break; | 26 | 9 | case 6: cb(simdjson::dom::array{});break; | 27 | 1 | case 7: cb(simdjson::dom::object{});break; | 28 | 58 | } | 29 | 58 | }; |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_1::operator()<LLVMFuzzerTestOneInput::$_3>(LLVMFuzzerTestOneInput::$_3) const Line | Count | Source | 17 | 74 | auto invoke_with_type=[selecttype](auto cb) { | 18 | 74 | using constcharstar=const char*; | 19 | 74 | switch(selecttype) { | 20 | 31 | case 0: cb(bool{});break; | 21 | 5 | case 1: cb(double{});break; | 22 | 8 | case 2: cb(uint64_t{});break; | 23 | 6 | case 3: cb(int64_t{});break; | 24 | 2 | case 4: cb(std::string_view{});break; | 25 | 12 | case 5: cb(constcharstar{});break; | 26 | 7 | case 6: cb(simdjson::dom::array{});break; | 27 | 3 | case 7: cb(simdjson::dom::object{});break; | 28 | 74 | } | 29 | 74 | }; |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_1::operator()<LLVMFuzzerTestOneInput::$_4>(LLVMFuzzerTestOneInput::$_4) const Line | Count | Source | 17 | 618 | auto invoke_with_type=[selecttype](auto cb) { | 18 | 618 | using constcharstar=const char*; | 19 | 618 | switch(selecttype) { | 20 | 79 | case 0: cb(bool{});break; | 21 | 82 | case 1: cb(double{});break; | 22 | 202 | case 2: cb(uint64_t{});break; | 23 | 171 | case 3: cb(int64_t{});break; | 24 | 19 | case 4: cb(std::string_view{});break; | 25 | 9 | case 5: cb(constcharstar{});break; | 26 | 21 | case 6: cb(simdjson::dom::array{});break; | 27 | 35 | case 7: cb(simdjson::dom::object{});break; | 28 | 618 | } | 29 | 618 | }; |
|
30 | | |
31 | 10.7k | const auto index = fd.get<size_t>(); |
32 | | |
33 | | // split the remainder of the document into strings |
34 | 10.7k | auto strings = fd.splitIntoStrings(); |
35 | 10.8k | while (strings.size() < 2) { |
36 | 68 | strings.emplace_back(); |
37 | 68 | } |
38 | 10.7k | const auto str = strings[0]; |
39 | | |
40 | | // exit if there was too little data |
41 | 10.7k | if (!fd) |
42 | 8 | return 0; |
43 | | |
44 | 10.7k | simdjson::dom::parser parser; |
45 | 10.7k | simdjson_unused simdjson::dom::element elem; |
46 | 10.7k | simdjson_unused auto error = parser.parse(strings[1]).get(elem); |
47 | | |
48 | 10.7k | if (error) |
49 | 4.40k | return 0; |
50 | | |
51 | 6.36k | #define CASE(num, fun) \ |
52 | 6.36k | case num: { \ |
53 | 1.96k | simdjson_unused auto v = elem.fun(); \ |
54 | 1.96k | break; \ |
55 | 1.96k | } |
56 | 6.36k | #define CASE2(num, fun) \ |
57 | 6.36k | case num: { \ |
58 | 2.55k | simdjson_unused auto v = elem fun; \ |
59 | 2.55k | break; \ |
60 | 2.55k | } |
61 | 6.36k | #if SIMDJSON_EXCEPTIONS |
62 | 6.36k | try { |
63 | 6.36k | #endif |
64 | | |
65 | 6.36k | switch (action) { |
66 | 360 | CASE(0, type); |
67 | 87 | CASE(1, get_array); |
68 | 73 | CASE(2, get_object); |
69 | 87 | CASE(3, get_c_str); |
70 | 60 | CASE(4, get_string_length); |
71 | 34 | CASE(5, get_string); |
72 | 38 | CASE(6, get_int64); |
73 | 43 | CASE(7, get_uint64); |
74 | 41 | CASE(8, get_double); |
75 | 47 | CASE(9, get_bool); |
76 | 66 | CASE(10, is_array); |
77 | 45 | CASE(11, is_object); |
78 | 62 | CASE(12, is_string); |
79 | 83 | CASE(13, is_int64); |
80 | 78 | CASE(14, is_uint64); |
81 | 79 | CASE(15, is_double); |
82 | 338 | CASE(16, is_number); |
83 | 60 | CASE(17, is_bool); |
84 | 84 | CASE(18, is_null); |
85 | | // element.is<>() : |
86 | 126 | case 19: { |
87 | 126 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.is<decltype (t)>(); }); fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_0::operator()<bool>(bool) const Line | Count | Source | 87 | 64 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.is<decltype (t)>(); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_0::operator()<double>(double) const Line | Count | Source | 87 | 17 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.is<decltype (t)>(); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_0::operator()<unsigned long>(unsigned long) const Line | Count | Source | 87 | 7 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.is<decltype (t)>(); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_0::operator()<long>(long) const Line | Count | Source | 87 | 3 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.is<decltype (t)>(); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_0::operator()<std::__1::basic_string_view<char, std::__1::char_traits<char> > >(std::__1::basic_string_view<char, std::__1::char_traits<char> >) const Line | Count | Source | 87 | 12 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.is<decltype (t)>(); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_0::operator()<char const*>(char const*) const Line | Count | Source | 87 | 3 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.is<decltype (t)>(); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_0::operator()<simdjson::dom::array>(simdjson::dom::array) const Line | Count | Source | 87 | 18 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.is<decltype (t)>(); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_0::operator()<simdjson::dom::object>(simdjson::dom::object) const Line | Count | Source | 87 | 2 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.is<decltype (t)>(); }); |
|
88 | 126 | } break; |
89 | | |
90 | | // CASE(xx,get); |
91 | 58 | case 20: { |
92 | 58 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.get<decltype (t)>(); }); fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_2::operator()<bool>(bool) const Line | Count | Source | 92 | 13 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.get<decltype (t)>(); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_2::operator()<double>(double) const Line | Count | Source | 92 | 18 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.get<decltype (t)>(); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_2::operator()<unsigned long>(unsigned long) const Line | Count | Source | 92 | 11 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.get<decltype (t)>(); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_2::operator()<long>(long) const Line | Count | Source | 92 | 3 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.get<decltype (t)>(); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_2::operator()<std::__1::basic_string_view<char, std::__1::char_traits<char> > >(std::__1::basic_string_view<char, std::__1::char_traits<char> >) const Line | Count | Source | 92 | 1 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.get<decltype (t)>(); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_2::operator()<char const*>(char const*) const Line | Count | Source | 92 | 2 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.get<decltype (t)>(); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_2::operator()<simdjson::dom::array>(simdjson::dom::array) const Line | Count | Source | 92 | 9 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.get<decltype (t)>(); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_2::operator()<simdjson::dom::object>(simdjson::dom::object) const Line | Count | Source | 92 | 1 | invoke_with_type([&elem](auto t){ simdjson_unused auto v = elem.get<decltype (t)>(); }); |
|
93 | 58 | } break; |
94 | | |
95 | | // CASE(xx,tie); |
96 | 74 | case 21: { |
97 | 74 | invoke_with_type([&elem](auto t){ |
98 | 74 | simdjson::error_code ec; |
99 | 74 | simdjson::dom::element{elem}.tie(t,ec); }); fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_3::operator()<bool>(bool) const Line | Count | Source | 97 | 31 | invoke_with_type([&elem](auto t){ | 98 | 31 | simdjson::error_code ec; | 99 | 31 | simdjson::dom::element{elem}.tie(t,ec); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_3::operator()<double>(double) const Line | Count | Source | 97 | 5 | invoke_with_type([&elem](auto t){ | 98 | 5 | simdjson::error_code ec; | 99 | 5 | simdjson::dom::element{elem}.tie(t,ec); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_3::operator()<unsigned long>(unsigned long) const Line | Count | Source | 97 | 8 | invoke_with_type([&elem](auto t){ | 98 | 8 | simdjson::error_code ec; | 99 | 8 | simdjson::dom::element{elem}.tie(t,ec); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_3::operator()<long>(long) const Line | Count | Source | 97 | 6 | invoke_with_type([&elem](auto t){ | 98 | 6 | simdjson::error_code ec; | 99 | 6 | simdjson::dom::element{elem}.tie(t,ec); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_3::operator()<std::__1::basic_string_view<char, std::__1::char_traits<char> > >(std::__1::basic_string_view<char, std::__1::char_traits<char> >) const Line | Count | Source | 97 | 2 | invoke_with_type([&elem](auto t){ | 98 | 2 | simdjson::error_code ec; | 99 | 2 | simdjson::dom::element{elem}.tie(t,ec); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_3::operator()<char const*>(char const*) const Line | Count | Source | 97 | 12 | invoke_with_type([&elem](auto t){ | 98 | 12 | simdjson::error_code ec; | 99 | 12 | simdjson::dom::element{elem}.tie(t,ec); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_3::operator()<simdjson::dom::array>(simdjson::dom::array) const Line | Count | Source | 97 | 7 | invoke_with_type([&elem](auto t){ | 98 | 7 | simdjson::error_code ec; | 99 | 7 | simdjson::dom::element{elem}.tie(t,ec); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_3::operator()<simdjson::dom::object>(simdjson::dom::object) const Line | Count | Source | 97 | 3 | invoke_with_type([&elem](auto t){ | 98 | 3 | simdjson::error_code ec; | 99 | 3 | simdjson::dom::element{elem}.tie(t,ec); }); |
|
100 | 74 | } break; |
101 | | |
102 | 0 | #if SIMDJSON_EXCEPTIONS |
103 | | // cast to type |
104 | 618 | case 22: { |
105 | 618 | invoke_with_type([&elem](auto t){ |
106 | 618 | using T=decltype(t); |
107 | 618 | simdjson_unused auto v = static_cast<T>(elem); }); fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_4::operator()<bool>(bool) const Line | Count | Source | 105 | 79 | invoke_with_type([&elem](auto t){ | 106 | 79 | using T=decltype(t); | 107 | 79 | simdjson_unused auto v = static_cast<T>(elem); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_4::operator()<double>(double) const Line | Count | Source | 105 | 82 | invoke_with_type([&elem](auto t){ | 106 | 82 | using T=decltype(t); | 107 | 82 | simdjson_unused auto v = static_cast<T>(elem); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_4::operator()<unsigned long>(unsigned long) const Line | Count | Source | 105 | 202 | invoke_with_type([&elem](auto t){ | 106 | 202 | using T=decltype(t); | 107 | 202 | simdjson_unused auto v = static_cast<T>(elem); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_4::operator()<long>(long) const Line | Count | Source | 105 | 171 | invoke_with_type([&elem](auto t){ | 106 | 171 | using T=decltype(t); | 107 | 171 | simdjson_unused auto v = static_cast<T>(elem); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_4::operator()<std::__1::basic_string_view<char, std::__1::char_traits<char> > >(std::__1::basic_string_view<char, std::__1::char_traits<char> >) const Line | Count | Source | 105 | 19 | invoke_with_type([&elem](auto t){ | 106 | 19 | using T=decltype(t); | 107 | 19 | simdjson_unused auto v = static_cast<T>(elem); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_4::operator()<char const*>(char const*) const Line | Count | Source | 105 | 9 | invoke_with_type([&elem](auto t){ | 106 | 9 | using T=decltype(t); | 107 | 9 | simdjson_unused auto v = static_cast<T>(elem); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_4::operator()<simdjson::dom::array>(simdjson::dom::array) const Line | Count | Source | 105 | 21 | invoke_with_type([&elem](auto t){ | 106 | 21 | using T=decltype(t); | 107 | 21 | simdjson_unused auto v = static_cast<T>(elem); }); |
fuzz_element.cpp:auto LLVMFuzzerTestOneInput::$_4::operator()<simdjson::dom::object>(simdjson::dom::object) const Line | Count | Source | 105 | 35 | invoke_with_type([&elem](auto t){ | 106 | 35 | using T=decltype(t); | 107 | 35 | simdjson_unused auto v = static_cast<T>(elem); }); |
|
108 | 618 | } break; |
109 | | |
110 | 117 | CASE(23, begin); |
111 | 83 | CASE(24, end); |
112 | 0 | #endif |
113 | 255 | CASE2(25, [str]); |
114 | 1.09k | CASE2(26, .at_pointer(str)); |
115 | | // CASE2(xx,at(str)); deprecated |
116 | 492 | CASE2(28, .at(index)); |
117 | 331 | CASE2(29, .at_key(str)); |
118 | 384 | CASE2(30, .at_key_case_insensitive(str)); |
119 | 909 | case 31: { NulOStream os; |
120 | 909 | simdjson_unused auto dumpstatus = elem.dump_raw_tape(os);} ;break; |
121 | 56 | default: |
122 | 56 | return 0; |
123 | 6.36k | } |
124 | 6.36k | #undef CASE |
125 | 6.36k | #undef CASE2 |
126 | | |
127 | 6.36k | #if SIMDJSON_EXCEPTIONS |
128 | 6.36k | } catch (std::exception &) { |
129 | | // do nothing |
130 | 664 | } |
131 | 0 | #endif |
132 | | |
133 | 6.30k | return 0; |
134 | 6.36k | } |