Coverage Report

Created: 2025-08-26 06:12

/src/h3/src/apps/fuzzers/fuzzerHierarchy.c
Line
Count
Source
1
/*
2
 * Copyright 2021 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 cellToParent and cellToChildren functions
18
 */
19
20
#include "aflHarness.h"
21
#include "h3api.h"
22
#include "utility.h"
23
24
280
#define MAX_CHILDREN_DIFF 10
25
26
typedef struct {
27
    H3Index index;
28
    int parentRes;
29
    int childRes;
30
} inputArgs;
31
32
288
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
33
288
    if (size < sizeof(inputArgs)) {
34
6
        return 0;
35
6
    }
36
282
    const inputArgs *args = (const inputArgs *)data;
37
38
282
    H3Index parent;
39
282
    H3_EXPORT(cellToParent)(args->index, args->parentRes, &parent);
40
41
282
    H3Index out;
42
282
    H3_EXPORT(cellToCenterChild)(args->index, args->childRes, &out);
43
44
    // Check for underflow before using args->childRes in subtraction.
45
    // getResolution will always produce outputs in the range of [0, 15], never
46
    // negative.
47
282
    if (args->childRes >= INT32_MIN + H3_EXPORT(getResolution)(args->index)) {
48
280
        int resDiff = args->childRes - H3_EXPORT(getResolution)(args->index);
49
280
        if (resDiff < MAX_CHILDREN_DIFF) {
50
232
            int64_t childrenSize;
51
232
            H3Error err = H3_EXPORT(cellToChildrenSize)(
52
232
                args->index, args->childRes, &childrenSize);
53
232
            if (!err) {
54
142
                H3Index *children = calloc(childrenSize, sizeof(H3Index));
55
142
                H3_EXPORT(cellToChildren)
56
142
                (args->index, args->childRes, children);
57
142
                free(children);
58
142
            }
59
232
        }
60
280
    }
61
282
    return 0;
62
288
}
63
64
AFL_HARNESS_MAIN(sizeof(inputArgs));