/src/spotify-json/fuzzers/fuzz_decode.cpp
Line | Count | Source |
1 | | #include <string> |
2 | | #include <stdint.h> |
3 | | #include <spotify/json/codec/number.hpp> |
4 | | #include <spotify/json/codec/object.hpp> |
5 | | #include <spotify/json/decode.hpp> |
6 | | #include <spotify/json/encoded_value.hpp> |
7 | | |
8 | | namespace { |
9 | | struct custom_obj { |
10 | | std::string val; |
11 | | }; |
12 | | } |
13 | | |
14 | | template <> |
15 | | struct spotify::json::default_codec_t<custom_obj> { |
16 | 2.41k | static codec::object_t<custom_obj> codec() { |
17 | 2.41k | auto codec = codec::object<custom_obj>(); |
18 | 2.41k | codec.required("x", &custom_obj::val); |
19 | 2.41k | return codec; |
20 | 2.41k | } |
21 | | }; |
22 | | |
23 | 2.41k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
24 | 2.41k | custom_obj obj; |
25 | 2.41k | std::string input(reinterpret_cast<const char*>(data), size); |
26 | 2.41k | spotify::json::try_decode(obj, input); |
27 | 2.41k | return 0; |
28 | 2.41k | } |