]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/opentelemetry-cpp/third_party/nlohmann-json/test/src/fuzzer-parse_cbor.cpp
3 __| | __| | | | JSON for Modern C++ (fuzz test support)
4 | | |__ | | | | | | version 3.10.5
5 |_____|_____|_____|_|___| https://github.com/nlohmann/json
7 This file implements a parser test suitable for fuzz testing. Given a byte
8 array data, it performs the following steps:
10 - j1 = from_cbor(data)
15 The provided function `LLVMFuzzerTestOneInput` can be used in different fuzzer
18 Licensed under the MIT License <http://opensource.org/licenses/MIT>.
23 #include <nlohmann/json.hpp>
25 using json
= nlohmann::json
;
27 // see http://llvm.org/docs/LibFuzzer.html
28 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data
, size_t size
)
32 // step 1: parse input
33 std::vector
<uint8_t> vec1(data
, data
+ size
);
34 json j1
= json::from_cbor(vec1
);
39 std::vector
<uint8_t> vec2
= json::to_cbor(j1
);
41 // parse serialization
42 json j2
= json::from_cbor(vec2
);
44 // serializations must match
45 assert(json::to_cbor(j2
) == vec2
);
47 catch (const json::parse_error
&)
49 // parsing a CBOR serialization must not fail
53 catch (const json::parse_error
&)
55 // parse errors are ok, because input may be random bytes
57 catch (const json::type_error
&)
59 // type errors can occur during parsing, too
61 catch (const json::out_of_range
&)
63 // out of range errors can occur during parsing, too
66 // return 0 - non-zero return values are reserved for future use