[H3] Use fuzzers from uber/h3 (#8406)

Use fuzzers from https://github.com/uber/h3/tree/master/src/apps/fuzzers
rather than the built in one. These additional fuzzers should provide
more complete coverage of the library, and should include all functions
currently fuzzed by oss-fuzz.

We can perhaps further clean up the build process to just pass
`$LIB_FUZZING_ENGINE` in to the fuzzers. In the mean time I just built
the fuzzers directly.
This commit is contained in:
Isaac Brodsky 2022-09-09 16:12:01 -07:00 committed by GitHub
parent c18654e7da
commit 44276ca688
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 87 deletions

View File

@ -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/

View File

@ -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

View File

@ -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 <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 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;
}