[abseil-cpp] Initial Integration (#3958)

Co-authored-by: Kabeer Seth <kabeerseth@google.com>
This commit is contained in:
kabeer27 2020-06-15 03:20:25 +00:00 committed by GitHub
parent 7c42471826
commit c06528180b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 269 additions and 0 deletions

30
projects/abseil-cpp/BUILD Normal file
View File

@ -0,0 +1,30 @@
# 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.
#
################################################################################
cc_binary(
name = "string_escape_fuzzer",
deps = ["@com_google_absl//absl/strings"],
srcs = ["string_escape_fuzzer.cc"],
)
cc_binary(
name = "string_utilities_fuzzer",
deps = [
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:cord"
],
srcs = ["string_utilities_fuzzer.cc"],
)

View File

@ -0,0 +1,30 @@
# 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.
#
################################################################################
FROM gcr.io/oss-fuzz-base/base-builder
RUN apt-get update && apt-get --no-install-recommends install -y build-essential make curl wget rsync
RUN echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list
RUN curl https://bazel.build/bazel-release.pub.gpg | apt-key add -
RUN apt-get update && apt-get install -y bazel
RUN curl -Lo /usr/bin/bazel \
https://github.com/bazelbuild/bazelisk/releases/download/v1.1.0/bazelisk-linux-amd64 \
&& \
chmod +x /usr/bin/bazel
RUN git clone --depth 1 https://github.com/abseil/abseil-cpp.git
COPY BUILD WORKSPACE build.sh string_escape_fuzzer.cc string_utilities_fuzzer.cc $SRC/

View File

@ -0,0 +1,20 @@
# 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.
#
################################################################################
local_repository(
name = "com_google_absl",
path = "abseil-cpp/",
)

View File

@ -0,0 +1,68 @@
# 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.
#
################################################################################
readonly EXTRA_BAZEL_FLAGS="$(
for f in ${CFLAGS}; do
echo "--conlyopt=${f}" "--linkopt=${f}"
done
for f in ${CXXFLAGS}; do
echo "--cxxopt=${f}" "--linkopt=${f}"
done
if [ "$SANITIZER" = "undefined" ]
then
# Bazel uses clang to link binary, which does not link clang_rt ubsan library for C++ automatically.
# See issue: https://github.com/bazelbuild/bazel/issues/8777
echo "--linkopt=\"$(find $(llvm-config --libdir) -name libclang_rt.ubsan_standalone_cxx-x86_64.a | head -1)\""
fi
)"
declare FUZZ_TARGETS=("string_escape_fuzzer" "string_utilities_fuzzer")
bazel build \
--verbose_failures \
--dynamic_mode=off \
--spawn_strategy=standalone \
--genrule_strategy=standalone \
--strip=never \
--linkopt=-pthread \
--copt=${LIB_FUZZING_ENGINE} \
--linkopt=${LIB_FUZZING_ENGINE} \
--linkopt=-lc++ \
${EXTRA_BAZEL_FLAGS} \
${FUZZ_TARGETS[*]}
if [ "$SANITIZER" = "coverage" ]
then
# The build invoker looks for sources in $SRC, but it turns out that we need
# to not be buried under src/, paths are expected at out/proc/self/cwd by
# the profiler.
declare -r REMAP_PATH="${OUT}/proc/self/cwd"
mkdir -p "${REMAP_PATH}"
mkdir -p "${REMAP_PATH}/external/com_google_absl"
rsync -av "${SRC}"/abseil-cpp/absl "${REMAP_PATH}/external/com_google_absl"
declare -r RSYNC_FILTER_ARGS=("--include" "*.h" "--include" "*.cc" "--include" \
"*.hpp" "--include" "*.cpp" "--include" "*.c" "--include" "*/" "--exclude" "*")
rsync -avLk "${RSYNC_FILTER_ARGS[@]}" "${SRC}"/bazel-out "${REMAP_PATH}"
rsync -avLkR "${RSYNC_FILTER_ARGS[@]}" "${HOME}" "${OUT}"
rsync -avLkR "${RSYNC_FILTER_ARGS[@]}" /tmp "${OUT}"
cp *fuzzer.cc "${OUT}/proc/self/cwd"
fi
cp "./bazel-bin/"*fuzzer "${OUT}/"

View File

@ -0,0 +1,3 @@
homepage: "abseil.io"
language: c++
primary_contact: "abseil-io@googlegroups.com"

View File

@ -0,0 +1,62 @@
// 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 <string>
#include "absl/strings/escaping.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
std::string str (reinterpret_cast<const char*>(data), size);
std::string escaped, unescaped;
escaped = absl::CHexEscape(str);
absl::CUnescape(escaped, &unescaped);
if (str != unescaped)
abort();
escaped = absl::CEscape(str);
absl::CUnescape(escaped, &unescaped);
if (str != unescaped)
abort();
escaped = absl::Utf8SafeCEscape(str);
absl::CUnescape(escaped, &unescaped);
if (str != unescaped)
abort();
escaped = absl::Utf8SafeCHexEscape(str);
absl::CUnescape(escaped, &unescaped);
if (str != unescaped)
abort();
std::string encoded, decoded;
absl::Base64Escape(str, &encoded);
absl::Base64Unescape(encoded, &decoded);
if (str != unescaped)
abort();
absl::WebSafeBase64Escape(str, &encoded);
absl::WebSafeBase64Unescape(encoded, &decoded);
if (str != decoded)
abort();
std::string hex_result, bytes_result;
hex_result = absl::BytesToHexString(str);
bytes_result = absl::HexStringToBytes(hex_result);
if (str != decoded)
abort();
return 0;
}

View File

@ -0,0 +1,56 @@
// 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 <string>
#include <fuzzer/FuzzedDataProvider.h>
#include "absl/strings/str_format.h"
#include "absl/strings/str_join.h"
#include "absl/strings/str_split.h"
#include "absl/strings/numbers.h"
#include "absl/strings/str_cat.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
FuzzedDataProvider fuzzed_data(data, size);
float float_value = fuzzed_data.ConsumeFloatingPoint<float>();
double double_value = fuzzed_data.ConsumeFloatingPoint<double>();
int int_value = fuzzed_data.ConsumeIntegral<int>();
bool bool_value = fuzzed_data.ConsumeBool();
std::string str1 = fuzzed_data.ConsumeRandomLengthString();
std::string str2 = fuzzed_data.ConsumeRemainingBytesAsString();
std::string float_str = absl::StrFormat("%g", float_value);
std::string double_str = absl::StrFormat("%g", double_value);
std::string int_str = absl::StrFormat("%d", int_value);
std::string bool_str = absl::StrFormat("%d", bool_value);
if (!absl::SimpleAtof(float_str, &float_value))
return 0;
if (!absl::SimpleAtod(double_str, &double_value))
return 0;
if (!absl::SimpleAtoi(int_str, &int_value))
return 0;
if (!absl::SimpleAtob(bool_str, &bool_value))
return 0;
absl::StrAppend(&str1, str2);
std::string str_result = absl::StrCat(str1, float_value, double_value, int_value, bool_value);
std::vector<std::string> v = absl::StrSplit(str_result, ".");
absl::StrJoin(v, ".");
return 0;
}