Coverage Report

Created: 2023-09-25 06:55

/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 "utility.h"
23
24
const int MAX_RES = 15;
25
const int MAX_SZ = 4000000;
26
27
662
void run(GeoPolygon *geoPolygon, uint32_t flags, int res) {
28
662
    int64_t sz;
29
662
    H3Error err = H3_EXPORT(maxPolygonToCellsSize)(geoPolygon, res, flags, &sz);
30
662
    if (!err && sz < MAX_SZ) {
31
569
        H3Index *out = calloc(sz, sizeof(H3Index));
32
569
        H3_EXPORT(polygonToCells)(geoPolygon, res, flags, out);
33
569
        free(out);
34
569
    }
35
662
}
36
37
664
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
38
664
    if (size < sizeof(int)) {
39
2
        return 0;
40
2
    }
41
42
662
    uint8_t res = *data;
43
662
    size_t vertsSize = size - 1;
44
662
    int numVerts = vertsSize / sizeof(LatLng);
45
46
662
    GeoPolygon geoPolygon;
47
662
    geoPolygon.numHoles = 0;
48
662
    geoPolygon.holes = NULL;
49
662
    geoPolygon.geoloop.numVerts = numVerts;
50
    // Offset by 1 since *data was used for `res`, above.
51
662
    geoPolygon.geoloop.verts = (LatLng *)(data + 1);
52
53
    // TODO: Fuzz the `flags` input as well when it has meaningful input
54
662
    run(&geoPolygon, 0, res);
55
56
662
    return 0;
57
664
}
58
59
AFL_HARNESS_MAIN(sizeof(H3Index) * 1024);