Line  | Count  | Source  | 
1  |  | /* Copyright 2021 Google LLC  | 
2  |  | Licensed under the Apache License, Version 2.0 (the "License");  | 
3  |  | you may not use this file except in compliance with the License.  | 
4  |  | You may obtain a copy of the License at  | 
5  |  |       http://www.apache.org/licenses/LICENSE-2.0  | 
6  |  | Unless required by applicable law or agreed to in writing, software  | 
7  |  | distributed under the License is distributed on an "AS IS" BASIS,  | 
8  |  | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
9  |  | See the License for the specific language governing permissions and  | 
10  |  | limitations under the License.  | 
11  |  | */  | 
12  |  | #include <iostream>  | 
13  |  | #include <bitset>  | 
14  |  | #include <cinttypes>  | 
15  |  | #include <unistd.h>  | 
16  |  | #include "parallel_hashmap/phmap_dump.h"  | 
17  |  | #include <fuzzer/FuzzedDataProvider.h>  | 
18  |  |  | 
19  |  | using phmap::flat_hash_map;  | 
20  |  | using namespace std;  | 
21  |  |  | 
22  | 595  | void serialise_test(const uint8_t *data, size_t size) { | 
23  | 595  |     phmap::flat_hash_map<unsigned int, int> table;  | 
24  | 595  |     FuzzedDataProvider fuzzed_data(data, size);  | 
25  | 595  |     const int num_items = fuzzed_data.ConsumeIntegral<int16_t>();  | 
26  |  |  | 
27  | 11.3M  |     for (int i=0; i < num_items; ++i)  { | 
28  | 11.3M  |         table.insert(typename phmap::flat_hash_map<unsigned int, int>::value_type(  | 
29  | 11.3M  |                     fuzzed_data.ConsumeIntegral<uint32_t>(),   | 
30  | 11.3M  |                     fuzzed_data.ConsumeIntegral<int32_t>()));  | 
31  | 11.3M  |     }  | 
32  |  |  | 
33  | 595  |     phmap::BinaryOutputArchive ar_out("/dump.data"); | 
34  | 595  |     table.phmap_dump(ar_out);  | 
35  |  |  | 
36  |  |     //MapType table_in;  | 
37  | 595  |     phmap::flat_hash_map<unsigned int, int> table_in;  | 
38  | 595  |     phmap::BinaryInputArchive ar_in("/dump.data"); | 
39  | 595  |     table_in.phmap_load(ar_in);  | 
40  |  |  | 
41  | 595  |     if(table == table_in) { | 
42  | 53  |         unlink("/dump.data"); | 
43  | 53  |         return;  | 
44  | 53  |     }  | 
45  | 542  |     unlink("/dump.data"); | 
46  | 542  | }  | 
47  |  |  | 
48  |  | void  | 
49  | 595  | test_assignments(const uint8_t *data, size_t size) { | 
50  | 595  |     phmap::flat_hash_map<std::string, std::string> email;  | 
51  | 595  |     FuzzedDataProvider fuzzed_data(data, size);  | 
52  | 595  |     const int num_items = fuzzed_data.ConsumeIntegral<int16_t>();  | 
53  | 11.3M  |     for (int i=0; i < num_items; ++i) { | 
54  | 11.3M  |             phmap::flat_hash_map<std::string, std::string>::value_type(  | 
55  | 11.3M  |                     fuzzed_data.ConsumeRandomLengthString(),   | 
56  | 11.3M  |                     fuzzed_data.ConsumeRandomLengthString());  | 
57  | 11.3M  |     }  | 
58  |  |     // Iterate through all of the items.  | 
59  | 595  |     for (const auto& n: email) {} | 
60  | 595  | }  | 
61  |  |  | 
62  | 595  | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { | 
63  | 595  |     serialise_test(data, size);  | 
64  | 595  |     test_assignments(data, size);  | 
65  | 595  |     return 0;  | 
66  | 595  | }  |