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