diff --git a/projects/h3/Dockerfile b/projects/h3/Dockerfile index 98f6e6ca4..ce4b04681 100644 --- a/projects/h3/Dockerfile +++ b/projects/h3/Dockerfile @@ -19,4 +19,4 @@ RUN apt-get update && apt-get install -y make autoconf automake libtool \ pkg-config RUN git clone --depth 1 https://github.com/uber/h3 WORKDIR h3 -COPY build.sh h3_fuzzer.c $SRC/ +COPY build.sh $SRC/ diff --git a/projects/h3/build.sh b/projects/h3/build.sh index 126327e2f..cd728b57c 100755 --- a/projects/h3/build.sh +++ b/projects/h3/build.sh @@ -17,18 +17,25 @@ mkdir build cd build -sed -i '21d' $SRC/h3/CMakeLists.txt cmake .. -make -j$(nproc) -$CC $CFLAGS -DH3_PREFIX="" \ - -I/src/h3/src/apps/applib/include \ - -I/src/h3/src/h3lib/include \ - -I/src/h3/build/src/h3lib/include \ - -o h3_fuzzer.o \ - -c $SRC/h3_fuzzer.c +make -j$(nproc) h3 -$CC $CFLAGS $LIB_FUZZING_ENGINE -rdynamic \ - h3_fuzzer.o \ - -o $OUT/h3_fuzzer \ +H3_BASE=/src/h3/ + +for fuzzer in $(find $H3_BASE/src/apps/fuzzers -name '*.c'); do + fuzzer_basename=$(basename -s .c $fuzzer) + # H3_USE_LIBFUZZER is needed so that H3 does not try to build its own + # implementation of `main` + $CC $CFLAGS -DH3_PREFIX="" \ + -DH3_USE_LIBFUZZER=1 \ + -I$H3_BASE/src/apps/applib/include \ + -I$H3_BASE/src/h3lib/include \ + -I$H3_BASE/build/src/h3lib/include \ + -o $fuzzer_basename.o \ + -c $fuzzer + + $CC $CFLAGS $LIB_FUZZING_ENGINE -rdynamic \ + $fuzzer_basename.o \ + -o $OUT/$fuzzer_basename \ lib/libh3.a - +done diff --git a/projects/h3/h3_fuzzer.c b/projects/h3/h3_fuzzer.c deleted file mode 100644 index 816d1c431..000000000 --- a/projects/h3/h3_fuzzer.c +++ /dev/null @@ -1,74 +0,0 @@ -/* -# Copyright 2021 Google LLC -# -# 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. -# -################################################################################ -*/ - -#include -#include -#include -#include - -// for h3NeighborRotations -#include "algos.h" -#include "h3api.h" -#include "utility.h" - -static const Direction DIGITS[7] = {CENTER_DIGIT, K_AXES_DIGIT, J_AXES_DIGIT, - JK_AXES_DIGIT, I_AXES_DIGIT, IK_AXES_DIGIT, - IJ_AXES_DIGIT}; - -int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - if (size < sizeof(H3Index)) { - return 0; - } - H3Index h3; - memcpy(&h3, data, sizeof(H3Index)); - - H3Index input[] = {h3, h3}; - int inputSize = sizeof(input) / sizeof(H3Index); - - // fuzz compactCells - H3Index *compacted = calloc(inputSize, sizeof(H3Index)); - H3Error errCompact = compactCells(input, compacted, inputSize); - - // fuzz uncompactCells - int compactedCount = 0; - for (int i = 0; i < inputSize; i++) { - if (compacted[i] != 0) { - compactedCount++; - } - } - if (compactedCount < 2) { - int uncompactRes = 10; - int64_t uncompactedSize; - H3Error err2 = - uncompactCellsSize(compacted, inputSize, uncompactRes, &uncompactedSize); - - H3Index *uncompacted = calloc(uncompactedSize, sizeof(H3Index)); - H3Error err3 = uncompactCells(compacted, compactedCount, uncompacted, - uncompactedSize, uncompactRes); - free(uncompacted); - } - - // fuzz h3NeighborRotations - int rotations = 0; - for (int i = 0; i < 7; i++) { - H3Index neighborRotationsOut; - h3NeighborRotations(h3, DIGITS[i], &rotations, &neighborRotationsOut); - } - free(compacted); - return 0; -}