/src/oatpp/fuzzers/oatpp/json/ObjectMapper.cpp
Line | Count | Source |
1 | | #include "oatpp/json/ObjectMapper.hpp" |
2 | | #include "oatpp/macro/codegen.hpp" |
3 | | |
4 | | typedef oatpp::utils::parser::Caret ParsingCaret; |
5 | | typedef oatpp::json::Serializer Serializer; |
6 | | typedef oatpp::json::Deserializer Deserializer; |
7 | | |
8 | | #include OATPP_CODEGEN_BEGIN(DTO) |
9 | | |
10 | | ENUM(TestEnum, v_int32, |
11 | | VALUE(A, 1, "a"), |
12 | | VALUE(B, 2, "b"), |
13 | | VALUE(C, 2, "c") |
14 | | ) |
15 | | |
16 | | class Empty : public oatpp::DTO { |
17 | | DTO_INIT(Empty, DTO) |
18 | | }; |
19 | | |
20 | | class Test1 : public oatpp::DTO { |
21 | | DTO_INIT(Test1, DTO) |
22 | | DTO_FIELD(Int8, i8); |
23 | | DTO_FIELD(UInt8, u8); |
24 | | DTO_FIELD(Int16, i16); |
25 | | DTO_FIELD(UInt16, u16); |
26 | | DTO_FIELD(Int32, i32); |
27 | | DTO_FIELD(UInt32, u32); |
28 | | DTO_FIELD(Int64, i64); |
29 | | DTO_FIELD(UInt64, u64); |
30 | | DTO_FIELD(Float32, f32); |
31 | | DTO_FIELD(Float64, f64); |
32 | | DTO_FIELD(Boolean, b); |
33 | | DTO_FIELD(String, s); |
34 | | DTO_FIELD(Enum<TestEnum>, e); |
35 | | DTO_FIELD(List<Float64>, l); |
36 | | DTO_FIELD(Vector<Int8>, v); |
37 | | DTO_FIELD(Fields<UInt32>, f); |
38 | | DTO_FIELD(UnorderedFields<UInt8>, uf); |
39 | | DTO_FIELD(UnorderedSet<Int64>, us); |
40 | | DTO_FIELD(Object<Empty>, obj, "o"); |
41 | | DTO_FIELD(Any, a); |
42 | | }; |
43 | | |
44 | 2.63k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
45 | 2.63k | oatpp::String input(reinterpret_cast<const char*>(data), size); |
46 | | |
47 | 2.63k | oatpp::json::ObjectMapper mapper; |
48 | 2.63k | mapper.deserializerConfig().mapper.allowUnknownFields = size & 0x01; |
49 | 2.63k | mapper.deserializerConfig().mapper.allowLexicalCasting = size & 0x02; |
50 | 2.63k | mapper.deserializerConfig().mapper.useUnqualifiedFieldNames = size & 0x04; |
51 | 2.63k | mapper.deserializerConfig().mapper.useUnqualifiedEnumNames = size & 0x08; |
52 | | |
53 | 2.63k | try { |
54 | 2.63k | const auto dto = mapper.readFromString<oatpp::Object<Test1>>(input); |
55 | 2.63k | mapper.writeToString(dto); |
56 | 2.63k | } catch(...) {} |
57 | | |
58 | 2.63k | return 0; |
59 | 2.63k | } |