/src/firebase-ios-sdk/Firestore/fuzzing/leveldb_fuzzer.cc
Line | Count | Source (jump to first uncovered line) |
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 | | #include <string> |
20 | | |
21 | | #include "Firestore/core/src/local/leveldb_key.h" |
22 | | #include "Firestore/core/src/local/leveldb_util.h" |
23 | | |
24 | | using firebase::firestore::local::LevelDbDocumentMutationKey; |
25 | | using firebase::firestore::local::LevelDbDocumentTargetKey; |
26 | | using firebase::firestore::local::LevelDbMutationKey; |
27 | | using firebase::firestore::local::LevelDbMutationQueueKey; |
28 | | using firebase::firestore::local::LevelDbQueryTargetKey; |
29 | | using firebase::firestore::local::LevelDbRemoteDocumentKey; |
30 | | using firebase::firestore::local::LevelDbTargetDocumentKey; |
31 | | using firebase::firestore::local::LevelDbTargetGlobalKey; |
32 | | using firebase::firestore::local::LevelDbTargetKey; |
33 | | using firebase::firestore::model::BatchId; |
34 | | using firebase::firestore::model::ResourcePath; |
35 | | |
36 | 4.87k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
37 | 4.87k | const char* str_ptr = reinterpret_cast<const char*>(data); |
38 | 4.87k | std::string str{str_ptr, size}; |
39 | 4.87k | leveldb::Slice slice = firebase::firestore::local::MakeSlice(str); |
40 | | |
41 | | // Test DescribeKey(std::string) which calls MakeSlice(std::string). |
42 | 4.87k | try { |
43 | 4.87k | firebase::firestore::local::DescribeKey(str); |
44 | 4.87k | } catch (...) { |
45 | | // Ignore caught errors and assertions. |
46 | 551 | } |
47 | | |
48 | | // Test LevelDbMutationKey methods. |
49 | 4.87k | try { |
50 | 4.87k | LevelDbMutationKey::KeyPrefix(str); |
51 | 4.87k | } catch (...) { |
52 | | // Ignore caught errors and assertions. |
53 | 0 | } |
54 | | |
55 | 4.87k | try { |
56 | 4.87k | BatchId batch_id{static_cast<int>(size)}; |
57 | 4.87k | LevelDbMutationKey::Key(str, batch_id); |
58 | 4.87k | } catch (...) { |
59 | | // Ignore caught errors and assertions. |
60 | 0 | } |
61 | | |
62 | 4.87k | try { |
63 | 4.87k | LevelDbMutationKey key; |
64 | 4.87k | (void)key.Decode(str); |
65 | 4.87k | } catch (...) { |
66 | | // Ignore caught errors and assertions. |
67 | 34 | } |
68 | | |
69 | | // Test LevelDbDocumentMutationKey methods. |
70 | 4.87k | try { |
71 | 4.87k | LevelDbDocumentMutationKey::KeyPrefix(str); |
72 | 4.87k | } catch (...) { |
73 | | // Ignore caught errors and assertions. |
74 | 0 | } |
75 | | |
76 | 4.87k | try { |
77 | 4.87k | LevelDbDocumentMutationKey key; |
78 | 4.87k | (void)key.Decode(str); |
79 | 4.87k | } catch (...) { |
80 | | // Ignore caught errors and assertions. |
81 | 34 | } |
82 | | |
83 | | // Test LevelDbMutationQueueKey methods. |
84 | 4.87k | try { |
85 | 4.87k | LevelDbMutationQueueKey::Key(str); |
86 | 4.87k | } catch (...) { |
87 | | // Ignore caught errors and assertions. |
88 | 0 | } |
89 | | |
90 | 4.87k | try { |
91 | 4.87k | LevelDbMutationQueueKey key; |
92 | 4.87k | (void)key.Decode(str); |
93 | 4.87k | } catch (...) { |
94 | | // Ignore caught errors and assertions. |
95 | 34 | } |
96 | | |
97 | | // Test LevelDbTargetGlobalKey methods. |
98 | 4.87k | try { |
99 | 4.87k | LevelDbTargetGlobalKey key; |
100 | 4.87k | (void)key.Decode(slice); |
101 | 4.87k | } catch (...) { |
102 | | // ignore caught errors and assertions. |
103 | 33 | } |
104 | | |
105 | | // Test LevelDbTargetKey methods. |
106 | 4.87k | try { |
107 | 4.87k | LevelDbTargetKey key; |
108 | 4.87k | (void)key.Decode(slice); |
109 | 4.87k | } catch (...) { |
110 | | // ignore caught errors and assertions. |
111 | 35 | } |
112 | | |
113 | | // Test LevelDbQueryTargetKey methods. |
114 | 4.87k | try { |
115 | 4.87k | LevelDbQueryTargetKey::KeyPrefix(str); |
116 | 4.87k | } catch (...) { |
117 | | // Ignore caught errors and assertions. |
118 | 0 | } |
119 | | |
120 | 4.87k | try { |
121 | 4.87k | LevelDbQueryTargetKey key; |
122 | 4.87k | (void)key.Decode(str); |
123 | 4.87k | } catch (...) { |
124 | | // Ignore caught errors and assertions. |
125 | 34 | } |
126 | | |
127 | | // Test LevelDbTargetDocumentKey methods. |
128 | 4.87k | try { |
129 | 4.87k | LevelDbTargetDocumentKey key; |
130 | 4.87k | (void)key.Decode(str); |
131 | 4.87k | } catch (...) { |
132 | | // Ignore caught errors and assertions. |
133 | 34 | } |
134 | | |
135 | | // Test LevelDbDocumentTargetKey methods. |
136 | 4.87k | try { |
137 | 4.87k | ResourcePath rp = ResourcePath::FromString(str); |
138 | 4.87k | LevelDbDocumentTargetKey::KeyPrefix(rp); |
139 | 4.87k | } catch (...) { |
140 | | // Ignore caught errors and assertions. |
141 | 277 | } |
142 | | |
143 | 4.87k | try { |
144 | 4.87k | LevelDbDocumentTargetKey key; |
145 | 4.87k | (void)key.Decode(str); |
146 | 4.87k | } catch (...) { |
147 | | // Ignore caught errors and assertions. |
148 | 34 | } |
149 | | |
150 | | // Test LevelDbRemoteDocumentKey methods. |
151 | 4.87k | try { |
152 | 4.87k | ResourcePath rp = ResourcePath::FromString(str); |
153 | 4.87k | LevelDbRemoteDocumentKey::KeyPrefix(rp); |
154 | 4.87k | } catch (...) { |
155 | | // Ignore caught errors and assertions. |
156 | 277 | } |
157 | | |
158 | 4.87k | try { |
159 | 4.87k | LevelDbRemoteDocumentKey key; |
160 | 4.87k | (void)key.Decode(str); |
161 | 4.87k | } catch (...) { |
162 | | // Ignore caught errors and assertions. |
163 | 34 | } |
164 | | |
165 | 4.87k | return 0; |
166 | 4.87k | } |