Coverage Report

Created: 2025-08-25 06:57

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