Skip to content

Commit

Permalink
add fuzzer for cellToChildPos (#732)
Browse files Browse the repository at this point in the history
* add fuzzer for cellToChildPos

* Remove assertion check
  • Loading branch information
isaacbrodsky committed Nov 29, 2022
1 parent e84cfa0 commit ab09177
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ set(OTHER_SOURCE_FILES
src/apps/fuzzers/fuzzerLocalIj.c
src/apps/fuzzers/fuzzerPolygonToCells.c
src/apps/fuzzers/fuzzerPolygonToCellsNoHoles.c
src/apps/fuzzers/fuzzerCellToChildPos.c
src/apps/fuzzers/fuzzerInternalAlgos.c
src/apps/benchmarks/benchmarkPolygonToCells.c
src/apps/benchmarks/benchmarkPolygon.c
Expand Down Expand Up @@ -508,6 +509,7 @@ if(BUILD_FUZZERS)
add_h3_fuzzer(fuzzerLocalIj src/apps/fuzzers/fuzzerLocalIj.c)
add_h3_fuzzer(fuzzerPolygonToCells src/apps/fuzzers/fuzzerPolygonToCells.c)
add_h3_fuzzer(fuzzerPolygonToCellsNoHoles src/apps/fuzzers/fuzzerPolygonToCellsNoHoles.c)
add_h3_fuzzer(fuzzerCellToChildPos src/apps/fuzzers/fuzzerCellToChildPos.c)
if(ENABLE_REQUIRES_ALL_SYMBOLS)
add_h3_fuzzer(fuzzerInternalAlgos src/apps/fuzzers/fuzzerInternalAlgos.c)
endif()
Expand Down
2 changes: 2 additions & 0 deletions src/apps/fuzzers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ The public API of H3 is covered in the following fuzzers:
| gridPathCells | [fuzzerLocalIj](./fuzzerLocalIj.c)
| cellToLocalIj | [fuzzerLocalIj](./fuzzerLocalIj.c)
| localIjToCell | [fuzzerLocalIj](./fuzzerLocalIj.c)
| cellToChildPos| [fuzzerCellToChildPos](./fuzzerCellToChildPos.c)
| childPosToCell| [fuzzerCellToChildPos](./fuzzerCellToChildPos.c)

## Internal function coverage

Expand Down
45 changes: 45 additions & 0 deletions src/apps/fuzzers/fuzzerCellToChildPos.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2022 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/** @file
* @brief Fuzzer program for cellToChildPos and related functions
*/

#include <assert.h>

#include "aflHarness.h"
#include "h3api.h"
#include "utility.h"

typedef struct {
H3Index index;
int64_t childPos;
int res;
} inputArgs;

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
if (size < sizeof(inputArgs)) {
return 0;
}
const inputArgs *args = (const inputArgs *)data;

int64_t posOut;
H3_EXPORT(cellToChildPos)(args->index, args->res, &posOut);
H3Index cellOut;
H3_EXPORT(childPosToCell)(args->childPos, args->index, args->res, &cellOut);
return 0;
}

AFL_HARNESS_MAIN(sizeof(inputArgs));

0 comments on commit ab09177

Please sign in to comment.