Coverage Report

Created: 2025-11-11 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/h3/src/apps/fuzzers/fuzzerPolygonToCellsNoHoles.c
Line
Count
Source
1
/*
2
 * Copyright 2022 Uber Technologies, Inc.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *         http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
/** @file
17
 * @brief Fuzzer program for polygonToCells and related functions, without holes
18
 */
19
20
#include "aflHarness.h"
21
#include "h3api.h"
22
#include "polygon.h"
23
#include "utility.h"
24
25
const int MAX_RES = 15;
26
const int MAX_SZ = 4000000;
27
28
1.80k
void run(GeoPolygon *geoPolygon, uint32_t flags, int res) {
29
1.80k
    int64_t sz;
30
1.80k
    H3Error err = H3_EXPORT(maxPolygonToCellsSize)(geoPolygon, res, flags, &sz);
31
1.80k
    if (!err && sz < MAX_SZ) {
32
1.40k
        H3Index *out = calloc(sz, sizeof(H3Index));
33
1.40k
        H3_EXPORT(polygonToCells)(geoPolygon, res, flags, out);
34
1.40k
        free(out);
35
1.40k
    }
36
1.80k
}
37
38
452
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
39
452
    if (size < sizeof(int)) {
40
2
        return 0;
41
2
    }
42
43
450
    uint8_t res = *data;
44
450
    size_t vertsSize = size - 1;
45
450
    int numVerts = vertsSize / sizeof(LatLng);
46
47
450
    GeoPolygon geoPolygon;
48
450
    geoPolygon.numHoles = 0;
49
450
    geoPolygon.holes = NULL;
50
450
    geoPolygon.geoloop.numVerts = numVerts;
51
    // Offset by 1 since *data was used for `res`, above.
52
450
    geoPolygon.geoloop.verts = (LatLng *)(data + 1);
53
54
2.25k
    for (uint32_t flags = 0; flags < CONTAINMENT_INVALID; flags++) {
55
1.80k
        run(&geoPolygon, flags, res);
56
1.80k
    }
57
58
450
    return 0;
59
452
}
60
61
AFL_HARNESS_MAIN(sizeof(H3Index) * 1024);