/src/boost_graph_graphml_fuzzer.cc
Line | Count | Source |
1 | | /* Copyright 2024 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 | | // The ideal place for this fuzz target is the boost repository. |
13 | | #include <boost/graph/adjacency_list.hpp> |
14 | | #include <boost/graph/graphml.hpp> |
15 | | #include <boost/range/irange.hpp> |
16 | | #ifdef DEBUG |
17 | | #include <iostream> |
18 | | #endif |
19 | | #include <string> |
20 | | #include <sstream> |
21 | | #include <fuzzer/FuzzedDataProvider.h> |
22 | | |
23 | | typedef boost::adjacency_list< |
24 | | boost::vecS, boost::vecS, boost::directedS, |
25 | | boost::property<boost::vertex_name_t, std::string>, |
26 | | boost::property<boost::edge_weight_t, double> |
27 | | > Graph; |
28 | | |
29 | | using namespace boost; |
30 | | |
31 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) |
32 | 16.0k | { |
33 | 16.0k | FuzzedDataProvider fdp(data, size); |
34 | 16.0k | try |
35 | 16.0k | { |
36 | 16.0k | Graph g; |
37 | 16.0k | boost::dynamic_properties dp(boost::ignore_other_properties); |
38 | 16.0k | std::stringstream input(fdp.ConsumeRemainingBytesAsString()); |
39 | 16.0k | read_graphml(input, g, dp); |
40 | 16.0k | auto viter = make_iterator_range(vertices(g)); |
41 | | #ifdef DEBUG |
42 | | for (auto v : viter) { |
43 | | std::cout << v << " "; |
44 | | } |
45 | | #endif |
46 | 16.0k | } catch(...) { |
47 | 10.6k | } |
48 | 16.0k | return 0; |
49 | 16.0k | } |