Coverage Report

Created: 2025-08-29 06:51

/src/igraph/fuzzing/bliss.cpp
Line
Count
Source
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
2.41k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
25
    // Data[0]  - splitting heuristic
26
    // Data[1:] - edges
27
28
2.41k
    igraph_t graph;
29
2.41k
    igraph_vector_int_t edges;
30
31
2.41k
    igraph_bliss_sh_t heurs[] = {
32
2.41k
        IGRAPH_BLISS_F, IGRAPH_BLISS_FL,
33
2.41k
        IGRAPH_BLISS_FS, IGRAPH_BLISS_FM,
34
2.41k
        IGRAPH_BLISS_FLM, IGRAPH_BLISS_FSM
35
2.41k
    };
36
2.41k
    igraph_bliss_sh_t heur;
37
38
2.41k
    const igraph_integer_t max_vcount  = 64;
39
40
2.41k
    igraph_set_warning_handler(igraph_warning_handler_ignore);
41
42
2.41k
    if (Size % 2 == 0 || Size > 512+1 || Size < 1) {
43
2
        return 0;
44
2
    }
45
46
2.41k
    if (Data[0] >= sizeof(heurs) / sizeof(heurs[0])) {
47
5
        return 0;
48
5
    }
49
50
2.40k
    heur = (igraph_bliss_sh_t) Data[0];
51
52
2.40k
    igraph_vector_int_init(&edges, Size-1);
53
87.2k
    for (size_t i=0; i < Size-1; ++i) {
54
84.8k
        VECTOR(edges)[i] = Data[i+1];
55
84.8k
    }
56
57
    /* Undirected */
58
2.40k
    if (igraph_create(&graph, &edges, 0, IGRAPH_UNDIRECTED) == IGRAPH_SUCCESS) {
59
2.40k
        if (igraph_vcount(&graph) <= max_vcount) {
60
2.37k
            igraph_bool_t multi;
61
62
2.37k
            igraph_has_multiple(&graph, &multi);
63
64
            /* Bliss does not support multigraphs and the input is currently not checked */
65
2.37k
            if (! multi) {
66
2.08k
                igraph_bliss_info_t info;
67
2.08k
                igraph_vector_int_list_t generators;
68
2.08k
                igraph_vector_int_list_init(&generators, 0);
69
2.08k
                igraph_automorphism_group_bliss(&graph, nullptr, &generators, heur, &info);
70
2.08k
                igraph_free(info.group_size);
71
2.08k
                igraph_vector_int_list_destroy(&generators);
72
2.08k
            }
73
2.37k
        }
74
75
2.40k
        igraph_destroy(&graph);
76
2.40k
    }
77
78
    /* Directed */
79
2.40k
    if (igraph_create(&graph, &edges, 0, IGRAPH_DIRECTED) == IGRAPH_SUCCESS) {
80
2.40k
        if (igraph_vcount(&graph) <= max_vcount) {
81
2.37k
            igraph_bool_t multi;
82
83
2.37k
            igraph_has_multiple(&graph, &multi);
84
85
            /* Bliss does not support multigraphs and the input is currently not checked */
86
2.37k
            if (! multi) {
87
2.35k
                igraph_bliss_info_t info;
88
2.35k
                igraph_vector_int_list_t generators;
89
2.35k
                igraph_vector_int_list_init(&generators, 0);
90
2.35k
                igraph_automorphism_group_bliss(&graph, nullptr, &generators, heur, &info);
91
2.35k
                igraph_free(info.group_size);
92
2.35k
                igraph_vector_int_list_destroy(&generators);
93
2.35k
            }
94
95
2.37k
        }
96
97
2.40k
        igraph_destroy(&graph);
98
2.40k
    }
99
100
2.40k
    igraph_vector_int_destroy(&edges);
101
102
2.40k
    IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY);
103
104
2.40k
    return 0;  // Non-zero return values are reserved for future use.
105
2.40k
}