Coverage Report

Created: 2026-05-30 06:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/geos/tests/fuzz/fuzz_geo2.c
Line
Count
Source
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <stdint.h>
4
#include <stdarg.h>
5
#include <string.h>
6
7
#include "geos_c.h"
8
9
static int initialized = 0;
10
FILE * flogOut;
11
12
void
13
0
notice(const char *fmt, ...) {
14
0
    va_list ap;
15
0
    fprintf( flogOut, "NOTICE: ");
16
0
    va_start (ap, fmt);
17
0
    vfprintf( flogOut, fmt, ap);
18
0
    va_end(ap);
19
0
    fprintf( flogOut, "\n" );
20
0
}
21
22
void
23
9.09k
log_and_exit(const char *fmt, ...) {
24
9.09k
    va_list ap;
25
9.09k
    fprintf( flogOut, "ERROR: ");
26
9.09k
    va_start (ap, fmt);
27
9.09k
    vfprintf( flogOut, fmt, ap);
28
9.09k
    va_end(ap);
29
9.09k
    fprintf( flogOut, "\n" );
30
9.09k
}
31
32
9.04k
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
33
9.04k
    if (initialized == 0) {
34
1
        flogOut = fopen("/dev/null", "wb");
35
1
        initGEOS(notice, log_and_exit);
36
1
        initialized = 1;
37
1
    }
38
9.04k
    size_t sep;
39
165M
    for (sep = 0; sep < Size; sep ++) {
40
165M
        if (Data[sep] == 0) {
41
9.03k
            break;
42
9.03k
        }
43
165M
    }
44
9.04k
    if (sep == Size) {
45
6
        return 0;
46
6
    }
47
9.03k
    GEOSGeometry *g1 = GEOSGeomFromWKT(Data);
48
49
9.03k
    if (g1 != NULL) {
50
8.12k
        GEOSGeometry *g2 = GEOSGeomFromWKB_buf(Data+sep, Size-sep);
51
8.12k
        if (g2 != NULL) {
52
7.50k
            size_t usize;
53
7.50k
            GEOSGeometry *g3 = GEOSIntersection(g1, g2);
54
7.50k
            GEOSGeom_destroy(g3);
55
7.50k
            g3 = GEOSDifference(g1, g2);
56
7.50k
            GEOSGeom_destroy(g3);
57
7.50k
            g3 = GEOSUnion(g1, g2);
58
7.50k
            GEOSGeom_destroy(g3);
59
7.50k
            unsigned char* uptr = GEOSGeomToWKB_buf(g1, &usize);
60
7.50k
            free(uptr);
61
7.50k
            GEOSGeom_destroy(g2);
62
7.50k
        }
63
8.12k
        char * r = GEOSGeomToWKT(g1);
64
8.12k
        free(r);
65
8.12k
        GEOSGeom_destroy(g1);
66
8.12k
    }
67
9.03k
    return 0;
68
9.04k
}
69