Coverage Report

Created: 2025-06-20 06:26

/src/igraph/fuzzing/misc_algos.cpp
Line
Count
Source
1
/*
2
   IGraph library.
3
   Copyright (C) 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 <cstdlib>
23
24
1.87k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
25
1.87k
    igraph_t graph;
26
1.87k
    igraph_vector_int_t edges;
27
28
1.87k
    igraph_set_warning_handler(igraph_warning_handler_ignore);
29
30
1.87k
    if (Size % 2 == 0 || Size > 512+1 || Size < 1) {
31
14
        return 0;
32
14
    }
33
34
1.85k
    igraph_vector_int_init(&edges, Size-1);
35
130k
    for (size_t i=0; i < Size-1; ++i) {
36
128k
        VECTOR(edges)[i] = Data[i+1];
37
128k
    }
38
39
1.85k
    igraph_rng_seed(igraph_rng_default(), 137);
40
41
    /* Directed */
42
1.85k
    if (igraph_create(&graph, &edges, Data[0], IGRAPH_DIRECTED) == IGRAPH_SUCCESS) {
43
1.85k
        igraph_vector_int_list_t ivl1;
44
1.85k
        igraph_vector_t v1, v2;
45
1.85k
        igraph_vector_int_t iv1, iv2;
46
1.85k
        igraph_t g;
47
48
1.85k
        igraph_vector_int_list_init(&ivl1, 0);
49
1.85k
        igraph_vector_init(&v1, 0);
50
1.85k
        igraph_vector_init(&v2, 0);
51
1.85k
        igraph_vector_int_init(&iv1, 0);
52
1.85k
        igraph_vector_int_init(&iv2, 0);
53
54
1.85k
        igraph_minimum_cycle_basis(&graph, &ivl1, -1, true, true, NULL);
55
1.85k
        igraph_fundamental_cycles(&graph, &ivl1, -1, -1, NULL);
56
57
1.85k
        igraph_motifs_randesu(&graph, &v1, 3, NULL);
58
59
1.85k
        igraph_list_triangles(&graph, &iv1);
60
61
1.85k
        igraph_ecc(&graph, &v1, igraph_ess_all(IGRAPH_EDGEORDER_ID), 3, false, true);
62
63
1.85k
        igraph_count_reachable(&graph, &iv1, IGRAPH_OUT);
64
1.85k
        igraph_transitive_closure(&graph, &g);
65
1.85k
        igraph_destroy(&g);
66
67
1.85k
        if (igraph_vcount(&graph) >= 2) {
68
1.83k
            igraph_get_all_simple_paths(&graph, &ivl1, 0, igraph_vss_1(1), -1, 5, IGRAPH_ALL);
69
1.83k
        }
70
71
1.85k
        if (igraph_vcount(&graph) >= 1) {
72
1.85k
            igraph_t subg;
73
74
1.85k
            igraph_random_walk(&graph, NULL, &iv1, &iv2, 0, IGRAPH_ALL, igraph_ecount(&graph), IGRAPH_RANDOM_WALK_STUCK_RETURN);
75
76
1.85k
            igraph_induced_subgraph(&graph, &subg, igraph_vss_vector(&iv1), IGRAPH_SUBGRAPH_AUTO);
77
1.85k
            igraph_destroy(&subg);
78
79
1.85k
            igraph_subgraph_from_edges(&graph, &subg, igraph_ess_vector(&iv2), true);
80
1.85k
            igraph_destroy(&subg);
81
82
1.85k
            igraph_reverse_edges(&graph, igraph_ess_vector(&iv2));
83
1.85k
        }
84
85
1.85k
        igraph_to_undirected(&graph, IGRAPH_TO_UNDIRECTED_COLLAPSE, NULL);
86
87
1.85k
        igraph_vector_resize(&v2, 4);
88
1.85k
        igraph_vector_null(&v2);
89
1.85k
        igraph_motifs_randesu(&graph, &v1, 4, &v2);
90
91
1.85k
        if (igraph_vcount(&graph) >= 1) {
92
1.85k
            igraph_random_walk(&graph, NULL, &iv1, &iv2, 0, IGRAPH_ALL, igraph_ecount(&graph), IGRAPH_RANDOM_WALK_STUCK_RETURN);
93
1.85k
        }
94
95
1.85k
        igraph_vector_int_destroy(&iv2);
96
1.85k
        igraph_vector_int_destroy(&iv1);
97
1.85k
        igraph_vector_destroy(&v2);
98
1.85k
        igraph_vector_destroy(&v1);
99
1.85k
        igraph_vector_int_list_destroy(&ivl1);
100
101
1.85k
        igraph_destroy(&graph);
102
1.85k
    }
103
104
1.85k
    igraph_vector_int_destroy(&edges);
105
106
1.85k
    IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY);
107
108
1.85k
    return 0;  // Non-zero return values are reserved for future use.
109
1.85k
}