Coverage Report

Created: 2025-11-14 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/igraph/fuzzing/read_graphml.cpp
Line
Count
Source
1
/*
2
   igraph library.
3
   Copyright (C) 2021-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
29.1k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
26
27
29.1k
    igraph_set_error_handler(igraph_error_handler_ignore);
28
29.1k
    igraph_set_warning_handler(igraph_warning_handler_ignore);
29
30
    // Turn on attribute handling
31
29.1k
    igraph_set_attribute_table(&igraph_cattribute_table);
32
33
    // Read input file
34
29.1k
    FILE *ifile = fmemopen((void*) data, size, "r");
35
29.1k
    if (!ifile) {
36
0
        return 0;
37
0
    }
38
39
    // Do the fuzzing
40
29.1k
    igraph_t g;
41
29.1k
    if (igraph_read_graph_graphml(&g, ifile, 0) == IGRAPH_SUCCESS) {
42
43
7.16k
        FILE *ofile = fopen("/dev/null", "w");
44
7.16k
        if (ofile) {
45
7.16k
            igraph_write_graph_graphml(&g, ofile, true);
46
7.16k
            fclose(ofile);
47
7.16k
        }
48
49
        // Clean up
50
7.16k
        igraph_destroy(&g);
51
7.16k
    }
52
53
    // no need to call igraph_destroy() if igraph_read_graph_graphml() returns an
54
    // error code as we don't have a valid graph object in that case
55
56
29.1k
    fclose(ifile);
57
58
29.1k
    IGRAPH_ASSERT(IGRAPH_FINALLY_STACK_EMPTY);
59
60
29.1k
    return 0;
61
29.1k
}