Coverage Report

Created: 2025-10-10 06:41

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
10.2k
log_and_exit(const char *fmt, ...) {
24
10.2k
    va_list ap;
25
10.2k
    fprintf( flogOut, "ERROR: ");
26
10.2k
    va_start (ap, fmt);
27
10.2k
    vfprintf( flogOut, fmt, ap);
28
10.2k
    va_end(ap);
29
10.2k
    fprintf( flogOut, "\n" );
30
10.2k
}
31
32
10.1k
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
33
10.1k
    if (initialized == 0) {
34
1
        flogOut = fopen("/dev/null", "wb");
35
1
        initGEOS(notice, log_and_exit);
36
1
        initialized = 1;
37
1
    }
38
10.1k
    size_t sep;
39
157M
    for (sep = 0; sep < Size; sep ++) {
40
157M
        if (Data[sep] == 0) {
41
10.1k
            break;
42
10.1k
        }
43
157M
    }
44
10.1k
    if (sep == Size) {
45
7
        return 0;
46
7
    }
47
10.1k
    GEOSGeometry *g1 = GEOSGeomFromWKT(Data);
48
49
10.1k
    if (g1 != NULL) {
50
9.13k
        GEOSGeometry *g2 = GEOSGeomFromWKB_buf(Data+sep, Size-sep);
51
9.13k
        if (g2 != NULL) {
52
8.41k
            size_t usize;
53
8.41k
            GEOSGeometry *g3 = GEOSIntersection(g1, g2);
54
8.41k
            GEOSGeom_destroy(g3);
55
8.41k
            g3 = GEOSDifference(g1, g2);
56
8.41k
            GEOSGeom_destroy(g3);
57
8.41k
            g3 = GEOSUnion(g1, g2);
58
8.41k
            GEOSGeom_destroy(g3);
59
8.41k
            unsigned char* uptr = GEOSGeomToWKB_buf(g1, &usize);
60
8.41k
            free(uptr);
61
8.41k
            GEOSGeom_destroy(g2);
62
8.41k
        }
63
9.13k
        char * r = GEOSGeomToWKT(g1);
64
9.13k
        free(r);
65
9.13k
        GEOSGeom_destroy(g1);
66
9.13k
    }
67
10.1k
    return 0;
68
10.1k
}
69