Coverage Report

Created: 2025-07-11 06:24

/src/igraph/fuzzing/centrality.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.25k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
25
1.25k
    igraph_t graph;
26
1.25k
    igraph_vector_int_t edges;
27
28
1.25k
    igraph_set_warning_handler(igraph_warning_handler_ignore);
29
30
1.25k
    if (Size % 2 == 0 || Size > 512+1 || Size < 1) {
31
14
        return 0;
32
14
    }
33
34
1.23k
    igraph_vector_int_init(&edges, Size-1);
35
76.3k
    for (size_t i=0; i < Size-1; ++i) {
36
75.1k
        VECTOR(edges)[i] = Data[i+1];
37
75.1k
    }
38
39
1.23k
    igraph_rng_seed(igraph_rng_default(), 42);
40
41
1.23k
    if (igraph_create(&graph, &edges, Data[0], IGRAPH_DIRECTED) == IGRAPH_SUCCESS) {
42
1.23k
        igraph_vector_t v;
43
1.23k
        igraph_vector_int_t iv;
44
1.23k
        igraph_bool_t b;
45
1.23k
        igraph_real_t r;
46
47
        /* Limit graph size for the sake of performance. */
48
1.23k
        if (igraph_vcount(&graph) <= 64) {
49
1.20k
            igraph_vector_init(&v, 0);
50
1.20k
            igraph_vector_int_init(&iv, 0);
51
52
1.20k
            igraph_betweenness_cutoff(&graph, &v, igraph_vss_all(), IGRAPH_ALL, NULL, 4);
53
1.20k
            igraph_betweenness_cutoff(&graph, &v, igraph_vss_all(), IGRAPH_IN, NULL, 5);
54
1.20k
            igraph_edge_betweenness_cutoff(&graph, &v, IGRAPH_DIRECTED, NULL, 4);
55
1.20k
            igraph_edge_betweenness_cutoff(&graph, &v, IGRAPH_UNDIRECTED, NULL, 3);
56
1.20k
            if (igraph_vcount(&graph) >= 10) {
57
1.11k
                igraph_betweenness_subset(&graph, &v, igraph_vss_all(), IGRAPH_DIRECTED, igraph_vss_range(0,5), igraph_vss_range(5,10), NULL);
58
1.11k
                igraph_edge_betweenness_subset(&graph, &v, igraph_ess_all(IGRAPH_EDGEORDER_ID), IGRAPH_DIRECTED, igraph_vss_range(0,10), igraph_vss_range(0,10), NULL);
59
1.11k
            }
60
1.20k
            igraph_closeness_cutoff(&graph, &v, &iv, &b, igraph_vss_all(), IGRAPH_ALL, NULL, true, 3);
61
1.20k
            igraph_closeness_cutoff(&graph, &v, &iv, &b, igraph_vss_all(), IGRAPH_OUT, NULL, true, 4);
62
1.20k
            igraph_harmonic_centrality_cutoff(&graph, &v, igraph_vss_all(), IGRAPH_ALL, NULL, true, 3);
63
1.20k
            igraph_harmonic_centrality_cutoff(&graph, &v, igraph_vss_all(), IGRAPH_IN, NULL, true, 4);
64
1.20k
            igraph_global_efficiency(&graph, NULL, &r, IGRAPH_DIRECTED);
65
1.20k
            igraph_local_efficiency(&graph, NULL, &v, igraph_vss_all(), IGRAPH_DIRECTED, IGRAPH_OUT);
66
1.20k
            igraph_transitivity_undirected(&graph, &r, IGRAPH_TRANSITIVITY_NAN);
67
1.20k
            igraph_transitivity_local_undirected(&graph, &v, igraph_vss_all(), IGRAPH_TRANSITIVITY_NAN);
68
1.20k
            igraph_transitivity_avglocal_undirected(&graph, &r, IGRAPH_TRANSITIVITY_ZERO);
69
1.20k
            igraph_count_adjacent_triangles(&graph, &v, igraph_vss_all());
70
1.20k
            igraph_pagerank(&graph, IGRAPH_PAGERANK_ALGO_PRPACK, &v, &r, igraph_vss_all(), IGRAPH_DIRECTED, 0.6, NULL, NULL);
71
1.20k
            igraph_constraint(&graph, &v, igraph_vss_all(), NULL);
72
1.20k
            igraph_spanner(&graph, &iv, 2.34, NULL);
73
74
1.20k
            igraph_to_undirected(&graph, IGRAPH_TO_UNDIRECTED_COLLAPSE, NULL);
75
1.20k
            igraph_simplify(&graph, /* remove_multiple */ true, /* remove_loops */ false, NULL);
76
1.20k
            igraph_trussness(&graph, &iv);
77
78
1.20k
            igraph_vector_int_destroy(&iv);
79
1.20k
            igraph_vector_destroy(&v);
80
1.20k
        }
81
82
1.23k
        igraph_destroy(&graph);
83
1.23k
    }
84
85
1.23k
    igraph_vector_int_destroy(&edges);
86
87
1.23k
    IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY);
88
89
1.23k
    return 0;  // Non-zero return values are reserved for future use.
90
1.23k
}