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