diff --git a/projects/google-py-crc32c/Dockerfile b/projects/google-py-crc32c/Dockerfile new file mode 100644 index 000000000..aa3fbbf67 --- /dev/null +++ b/projects/google-py-crc32c/Dockerfile @@ -0,0 +1,20 @@ +# Copyright 2022 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-python +RUN git clone https://github.com/googleapis/python-crc32c +COPY build.sh *.py $SRC/ +WORKDIR python-crc32c diff --git a/projects/google-py-crc32c/build.sh b/projects/google-py-crc32c/build.sh new file mode 100644 index 000000000..ee4a78c79 --- /dev/null +++ b/projects/google-py-crc32c/build.sh @@ -0,0 +1,45 @@ +#!/bin/bash -eu +# Copyright 2022 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. +# +################################################################################ + +git submodule update --init --recursive + +mkdir usr +export CRC32C_INSTALL_PREFIX=$(pwd)/usr + +mkdir google_crc32c/build +cd google_crc32c/build +cmake \ + -DCMAKE_BUILD_TYPE=Release \ + -DCRC32C_BUILD_TESTS=no \ + -DCRC32C_BUILD_BENCHMARKS=no \ + -DBUILD_SHARED_LIBS=yes \ + -DCMAKE_INSTALL_PREFIX:PATH=${CRC32C_INSTALL_PREFIX} \ + ../ +make all install +cd ../../ + + +python3 setup.py build_ext \ + --include-dirs=$(pwd)/usr/include \ + --library-dirs=$(pwd)/usr/lib \ + --rpath=$(pwd)/usr/lib +pip3 install -e .[testing] + +# Build fuzzers in $OUT. +for fuzzer in $(find $SRC -name 'fuzz_*.py'); do + compile_python_fuzzer $fuzzer +done diff --git a/projects/google-py-crc32c/fuzz_checksum.py b/projects/google-py-crc32c/fuzz_checksum.py new file mode 100644 index 000000000..1693f5164 --- /dev/null +++ b/projects/google-py-crc32c/fuzz_checksum.py @@ -0,0 +1,33 @@ +#!/usr/bin/python3 +# Copyright 2022 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. + +import atheris +import sys + +with atheris.instrument_imports(): + import google_crc32c + +def TestOneInput(data): + val1 = google_crc32c.value(data) + val2 = google_crc32c.Checksum(data)._crc + assert val1 == val2 + + +def main(): + atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True) + atheris.Fuzz() + +if __name__ == "__main__": + main() diff --git a/projects/google-py-crc32c/project.yaml b/projects/google-py-crc32c/project.yaml new file mode 100644 index 000000000..e401426a3 --- /dev/null +++ b/projects/google-py-crc32c/project.yaml @@ -0,0 +1,11 @@ +fuzzing_engines: +- libfuzzer +homepage: https://github.com/googleapis/python-crc32c +language: python +main_repo: https://github.com/googleapis/python-crc32c +sanitizers: +- address +- undefined +vendor_ccs: +- david@adalogics.com +- adam@adalogics.com