aboutsummaryrefslogtreecommitdiff
path: root/projects/s2geometry
diff options
context:
space:
mode:
authorAdamKorcz <44787359+AdamKorcz@users.noreply.github.com>2021-06-05 17:05:18 +0100
committerGitHub <noreply@github.com>2021-06-05 09:05:18 -0700
commite365fe365464a629d7d224ab5744b3fcd056cb00 (patch)
tree2f4dbbd154a01c243b7b7c92eb4a07d99d411ea0 /projects/s2geometry
parentf0fbabd25917f8ee7d89edc1df86bcea7a415ba1 (diff)
downloadoss-fuzz-e365fe365464a629d7d224ab5744b3fcd056cb00.tar.gz
[s2geometry] Initial integration (#5783)
Diffstat (limited to 'projects/s2geometry')
-rw-r--r--projects/s2geometry/Dockerfile43
-rwxr-xr-xprojects/s2geometry/build.sh34
-rw-r--r--projects/s2geometry/project.yaml10
-rw-r--r--projects/s2geometry/s2_fuzzer.cc99
4 files changed, 186 insertions, 0 deletions
diff --git a/projects/s2geometry/Dockerfile b/projects/s2geometry/Dockerfile
new file mode 100644
index 000000000..8f58a555a
--- /dev/null
+++ b/projects/s2geometry/Dockerfile
@@ -0,0 +1,43 @@
+# 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 -y install \
+ libgflags-dev \
+ libgoogle-glog-dev \
+ libgtest-dev libssl-dev \
+ make \
+ curl
+
+# OpenSSL
+ARG OPENSSL_VERSION=1.1.1g
+ARG OPENSSL_HASH=ddb04774f1e32f0c49751e21b67216ac87852ceb056b75209af2443400636d46
+RUN set -ex \
+ && curl -s -O https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz \
+ && echo "${OPENSSL_HASH} openssl-${OPENSSL_VERSION}.tar.gz" | sha256sum -c \
+ && tar -xzf openssl-${OPENSSL_VERSION}.tar.gz \
+ && cd openssl-${OPENSSL_VERSION} \
+ && ./Configure linux-x86_64 no-shared --static "$CFLAGS" \
+ && make build_generated \
+ && make libcrypto.a \
+ && make install
+
+RUN git clone https://github.com/google/s2geometry
+WORKDIR $SRC/s2geometry
+COPY build.sh \
+ s2_fuzzer.cc \
+ $SRC/
diff --git a/projects/s2geometry/build.sh b/projects/s2geometry/build.sh
new file mode 100755
index 000000000..1b7cd97e7
--- /dev/null
+++ b/projects/s2geometry/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 -DBUILD_SHARED_LIBS=OFF \
+ -DABSL_MIN_LOG_LEVEL=4 \
+ -DGTEST_ROOT=/usr/src/gtest ..
+make -j$(nproc)
+
+$CXX $CXXFLAGS -DABSL_MIN_LOG_LEVEL=4 \
+ -I/src/s2geometry/src \
+ -I/usr/src/gtest/include -std=c++11 \
+ -c $SRC/s2_fuzzer.cc \
+ -o s2_fuzzer.o
+
+$CXX $CXXFLAGS $LIB_FUZZING_ENGINE \
+ s2_fuzzer.o -o $OUT/s2_fuzzer \
+ /src/s2geometry/build/libs2.a \
+ /src/openssl-1.1.1g/libssl.a \
+ /src/openssl-1.1.1g/libcrypto.a
diff --git a/projects/s2geometry/project.yaml b/projects/s2geometry/project.yaml
new file mode 100644
index 000000000..8f53bde78
--- /dev/null
+++ b/projects/s2geometry/project.yaml
@@ -0,0 +1,10 @@
+homepage: "https://github.com/google/s2geometry"
+language: c++
+primary_contact: "jmr@google.com"
+auto_ccs:
+ - "Adam@adalogics.com"
+sanitizers:
+ - address
+ - undefined
+ - memory
+main_repo: "https://github.com/google/s2geometry"
diff --git a/projects/s2geometry/s2_fuzzer.cc b/projects/s2geometry/s2_fuzzer.cc
new file mode 100644
index 000000000..62050a0dc
--- /dev/null
+++ b/projects/s2geometry/s2_fuzzer.cc
@@ -0,0 +1,99 @@
+/*
+# Copyright 2020 Google 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.
+#
+################################################################################
+*/
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "s2/s2shapeutil_range_iterator.h"
+#include "s2/third_party/absl/strings/str_split.h"
+#include "s2/third_party/absl/strings/string_view.h"
+
+#include "s2/mutable_s2shape_index.h"
+#include "s2/s2text_format.h"
+
+// A string-splitter used to help validate the string
+// passed to s2
+static std::vector<absl::string_view> SplitString(absl::string_view str,
+ char separator) {
+ std::vector<absl::string_view> result =
+ absl::StrSplit(str, separator, absl::SkipWhitespace());
+ for (auto &e : result) {
+ e = absl::StripAsciiWhitespace(e);
+ }
+ return result;
+}
+
+// Null-terminates the fuzzers input test case
+char *null_terminated(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';
+ return new_str;
+}
+
+// Do a bit of validation that is also done by s2
+// We do them here since s2 would terminate if they
+// would return false inside s2.
+bool isValidFormat(char *nt_string, size_t size) {
+ int hash_count = 0;
+ for (int i = 0; i < size; i++) {
+ if (nt_string[i] == 35) {
+ hash_count++;
+ }
+ }
+ if (hash_count != 2) {
+ return false;
+ }
+
+ std::vector<absl::string_view> strs = SplitString(nt_string, '#');
+ size_t strs_size = strs.size();
+ if (strs.size() != 3) {
+ return false;
+ }
+
+ auto index1 = absl::make_unique<MutableS2ShapeIndex>();
+ if (s2textformat::MakeIndex(nt_string, &index1) == false) {
+ return false;
+ }
+ return true;
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+
+ if (size < 5) {
+ return 0;
+ }
+
+ char *nt_string = null_terminated(data, size);
+ if (nt_string == NULL) {
+ return 0;
+ }
+ if (isValidFormat(nt_string, size)) {
+ auto index = s2textformat::MakeIndex(nt_string);
+ s2shapeutil::RangeIterator it(*index);
+ if (!it.done()) {
+ it.Next();
+ }
+ }
+ free(nt_string);
+ return 0;
+}