/src/igraph/fuzzing/bliss_fuzzer.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | IGraph library. |
3 | | Copyright (C) 2021-2022 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 <cstdlib> |
23 | | |
24 | 14.0k | inline void check_err(int err) { |
25 | 14.0k | if (err) |
26 | 0 | abort(); |
27 | 14.0k | } |
28 | | |
29 | 2.10k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
30 | 2.10k | igraph_t graph; |
31 | 2.10k | igraph_vector_int_t edges; |
32 | | |
33 | 2.10k | igraph_set_error_handler(igraph_error_handler_ignore); |
34 | 2.10k | igraph_set_warning_handler(igraph_warning_handler_ignore); |
35 | | |
36 | 2.10k | if (Size % 2 == 1 || Size > 512) { |
37 | 13 | return 0; |
38 | 13 | } |
39 | | |
40 | 2.09k | check_err(igraph_vector_int_init(&edges, Size)); |
41 | 116k | for (size_t i=0; i < Size; ++i) { |
42 | 114k | VECTOR(edges)[i] = Data[i]; |
43 | 114k | } |
44 | | |
45 | | /* Undirected */ |
46 | 2.09k | if (! igraph_create(&graph, &edges, 0, IGRAPH_UNDIRECTED)) { |
47 | 2.09k | igraph_bool_t multi; |
48 | | |
49 | 2.09k | check_err(igraph_has_multiple(&graph, &multi)); |
50 | | |
51 | | /* Bliss does not support multigraphs and the input is currently not checked */ |
52 | 2.09k | if (! multi) { |
53 | 1.80k | igraph_bliss_info_t info; |
54 | 1.80k | igraph_vector_int_list_t generators; |
55 | 1.80k | check_err(igraph_vector_int_list_init(&generators, 0)); |
56 | 1.80k | check_err(igraph_automorphism_group(&graph, nullptr, &generators, IGRAPH_BLISS_FS, &info)); |
57 | 1.80k | igraph_free(info.group_size); |
58 | 1.80k | igraph_vector_int_list_destroy(&generators); |
59 | 1.80k | } |
60 | | |
61 | 2.09k | igraph_destroy(&graph); |
62 | 2.09k | } |
63 | | |
64 | | /* Directed */ |
65 | 2.09k | if (! igraph_create(&graph, &edges, 0, IGRAPH_DIRECTED)) { |
66 | 2.09k | igraph_bool_t multi; |
67 | | |
68 | 2.09k | check_err(igraph_has_multiple(&graph, &multi)); |
69 | | |
70 | | /* Bliss does not support multigraphs and the input is currently not checked */ |
71 | 2.09k | if (! multi) { |
72 | 2.06k | igraph_bliss_info_t info; |
73 | 2.06k | igraph_vector_int_list_t generators; |
74 | 2.06k | check_err(igraph_vector_int_list_init(&generators, 0)); |
75 | 2.06k | check_err(igraph_automorphism_group(&graph, nullptr, &generators, IGRAPH_BLISS_FS, &info)); |
76 | 2.06k | igraph_free(info.group_size); |
77 | 2.06k | igraph_vector_int_list_destroy(&generators); |
78 | 2.06k | } |
79 | | |
80 | 2.09k | igraph_destroy(&graph); |
81 | 2.09k | } |
82 | | |
83 | 2.09k | igraph_vector_int_destroy(&edges); |
84 | | |
85 | 2.09k | IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY); |
86 | | |
87 | 2.09k | return 0; // Non-zero return values are reserved for future use. |
88 | 2.09k | } |