/src/glaze/fuzzing/msgpack_reflection.cpp
Line | Count | Source |
1 | | #include <array> |
2 | | #include <cstddef> |
3 | | #include <cstdint> |
4 | | #include <glaze/glaze.hpp> |
5 | | #include <glaze/msgpack.hpp> |
6 | | #include <vector> |
7 | | |
8 | | struct my_struct |
9 | | { |
10 | | int i = 287; |
11 | | double d = 3.14; |
12 | | std::string hello = "Hello World"; |
13 | | std::array<uint64_t, 3> arr = {1, 2, 3}; |
14 | | }; |
15 | | |
16 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) |
17 | 670 | { |
18 | | // use a vector with null termination instead of a std::string to avoid |
19 | | // small string optimization to hide bounds problems |
20 | 670 | std::vector<char> buffer{Data, Data + Size}; |
21 | | |
22 | | // non-null terminated |
23 | 670 | { |
24 | 670 | const auto& input = buffer; |
25 | 670 | [[maybe_unused]] auto s = glz::read_msgpack<my_struct>(input); |
26 | 670 | } |
27 | | |
28 | | // null terminated |
29 | 670 | { |
30 | 670 | buffer.push_back('\0'); |
31 | 670 | const auto& input = buffer; |
32 | 670 | [[maybe_unused]] auto s = glz::read_msgpack<my_struct>(input); |
33 | 670 | } |
34 | | |
35 | 670 | return 0; |
36 | 670 | } |