/src/igraph/fuzzing/read_edgelist.cpp
Line | Count | Source |
1 | | /* |
2 | | igraph library. |
3 | | Copyright (C) 2022-2024 The igraph development team |
4 | | |
5 | | This program is free software; you can redistribute it and/or modify |
6 | | it under the terms of the GNU General Public License as published by |
7 | | the Free Software Foundation; either version 2 of the License, or |
8 | | (at your option) any later version. |
9 | | |
10 | | This program is distributed in the hope that it will be useful, |
11 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | GNU General Public License for more details. |
14 | | |
15 | | You should have received a copy of the GNU General Public License |
16 | | along with this program; if not, write to the Free Software |
17 | | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | | 02110-1301 USA |
19 | | */ |
20 | | |
21 | | #include <igraph.h> |
22 | | #include <cstdio> |
23 | | |
24 | | extern "C" |
25 | 28.8k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
26 | | |
27 | 28.8k | igraph_set_error_handler(igraph_error_handler_ignore); |
28 | 28.8k | igraph_set_warning_handler(igraph_warning_handler_ignore); |
29 | | |
30 | | // Read input file |
31 | 28.8k | FILE *ifile = fmemopen((void*) data, size, "r"); |
32 | 28.8k | if (!ifile) { |
33 | 0 | return 0; |
34 | 0 | } |
35 | | |
36 | | // Do the fuzzing |
37 | 28.8k | igraph_t g; |
38 | 28.8k | if (igraph_read_graph_edgelist(&g, ifile, 0, IGRAPH_UNDIRECTED) == IGRAPH_SUCCESS) { |
39 | | |
40 | 7.06k | FILE *ofile = fopen("/dev/null", "w"); |
41 | 7.06k | if (ofile) { |
42 | 7.06k | igraph_write_graph_edgelist(&g, ofile); |
43 | 7.06k | fclose(ofile); |
44 | 7.06k | } |
45 | | |
46 | | // Clean up |
47 | 7.06k | igraph_destroy(&g); |
48 | 7.06k | } |
49 | | |
50 | | // no need to call igraph_destroy() if igraph_read_graph_edgelist() returns an |
51 | | // error code as we don't have a valid graph object in that case |
52 | | |
53 | 28.8k | fclose(ifile); |
54 | | |
55 | 28.8k | IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY); |
56 | | |
57 | 28.8k | return 0; |
58 | 28.8k | } |