/src/firebase-ios-sdk/Firestore/fuzzing/serializer_fuzzer.cc
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2018 Google |
3 | | * |
4 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | | * you may not use this file except in compliance with the License. |
6 | | * You may obtain a copy of the License at |
7 | | * |
8 | | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | * |
10 | | * Unless required by applicable law or agreed to in writing, software |
11 | | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | | * See the License for the specific language governing permissions and |
14 | | * limitations under the License. |
15 | | */ |
16 | | |
17 | | #include <cstddef> |
18 | | #include <cstdint> |
19 | | |
20 | | #include "Firestore/Protos/nanopb/google/firestore/v1/document.nanopb.h" |
21 | | #include "Firestore/core/src/model/database_id.h" |
22 | | #include "Firestore/core/src/nanopb/message.h" |
23 | | #include "Firestore/core/src/nanopb/reader.h" |
24 | | #include "Firestore/core/src/remote/serializer.h" |
25 | | #include "Firestore/core/src/util/read_context.h" |
26 | | |
27 | | using firebase::firestore::google_firestore_v1_Value; |
28 | | using firebase::firestore::model::DatabaseId; |
29 | | using firebase::firestore::nanopb::Message; |
30 | | using firebase::firestore::nanopb::StringReader; |
31 | | using firebase::firestore::remote::Serializer; |
32 | | using firebase::firestore::util::ReadContext; |
33 | | |
34 | 1.92k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
35 | 1.92k | Serializer serializer{DatabaseId{"project", DatabaseId::kDefault}}; |
36 | 1.92k | try { |
37 | | // Try to decode the received data using the serializer. |
38 | 1.92k | StringReader reader{data, size}; |
39 | 1.92k | auto message = Message<google_firestore_v1_Value>::TryParse(&reader); |
40 | | //ReadContext; |
41 | | //serializerodeFieldValue(&context, *message); |
42 | 1.92k | } catch (...) { |
43 | | // Ignore caught errors and assertions because fuzz testing is looking for |
44 | | // crashes and memory errors. |
45 | 111 | } |
46 | 1.92k | return 0; |
47 | 1.92k | } |