diff --git a/projects/h3/Dockerfile b/projects/h3/Dockerfile new file mode 100644 index 000000000..98f6e6ca4 --- /dev/null +++ b/projects/h3/Dockerfile @@ -0,0 +1,22 @@ +# 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. +# +################################################################################ + +FROM gcr.io/oss-fuzz-base/base-builder +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/ diff --git a/projects/h3/build.sh b/projects/h3/build.sh new file mode 100755 index 000000000..bc35a2db8 --- /dev/null +++ b/projects/h3/build.sh @@ -0,0 +1,34 @@ +#!/bin/bash -eu +# 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. +# +################################################################################ + +mkdir build +cd build +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 + +$CC $CFLAGS $LIB_FUZZING_ENGINE -rdynamic \ + h3_fuzzer.o \ + -o $OUT/h3_fuzzer \ + lib/libh3.a + diff --git a/projects/h3/h3_fuzzer.c b/projects/h3/h3_fuzzer.c new file mode 100644 index 000000000..e0923e26a --- /dev/null +++ b/projects/h3/h3_fuzzer.c @@ -0,0 +1,75 @@ +/* +# 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 + +#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) { + char *new_str = (char *)malloc(size + 1); + if (new_str == NULL) { + return 0; + } + memcpy(new_str, data, size); + new_str[size] = '\0'; + + H3Index h3; + h3 = H3_EXPORT(stringToH3)(new_str); + + H3Index input[] = {h3, h3}; + int inputSize = sizeof(input) / sizeof(H3Index); + + // fuzz compactCells + H3Index *compacted = calloc(inputSize, sizeof(H3Index)); + int err = 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 = + uncompactCellsSize(compacted, inputSize, uncompactRes); + + H3Index *uncompacted = calloc(uncompactedSize, sizeof(H3Index)); + int err2 = uncompactCells(compacted, compactedCount, uncompacted, + uncompactedSize, uncompactRes); + free(uncompacted); + } + + // fuzz h3NeighborRotations + int rotations = 0; + for (int i = 0; i < 7; i++) { + h3NeighborRotations(h3, DIGITS[i], &rotations); + } + free(compacted); + free(new_str); + return 0; +} diff --git a/projects/h3/project.yaml b/projects/h3/project.yaml new file mode 100644 index 000000000..c56084a7c --- /dev/null +++ b/projects/h3/project.yaml @@ -0,0 +1,11 @@ +homepage: "https://github.com/uber/h3" +language: c +primary_contact: "isaac@isaacbrodsky.com" +auto_ccs: + - "Adam@adalogics.com" + - "h3-dev@googlegroups.com" +sanitizers: + - address + - undefined + - memory +main_repo: 'https://github.com/uber/h3'