From f40452d714b48b4130dbc5d199ce97f49df6b3ef Mon Sep 17 00:00:00 2001 From: DavidKorczynski Date: Tue, 28 Jun 2022 17:22:02 -0200 Subject: [PATCH] py-bigquery: initial integration (#7744) * py-bigquery: initial integration * rename project for the reasons described here https://github.com/google/oss-fuzz/pull/7900 * update pip and install grpcio in dockerfile --- projects/g-py-bigquery/Dockerfile | 22 ++++++++++ projects/g-py-bigquery/build.sh | 23 ++++++++++ projects/g-py-bigquery/fuzz_parser.py | 60 +++++++++++++++++++++++++++ projects/g-py-bigquery/project.yaml | 11 +++++ 4 files changed, 116 insertions(+) create mode 100644 projects/g-py-bigquery/Dockerfile create mode 100644 projects/g-py-bigquery/build.sh create mode 100644 projects/g-py-bigquery/fuzz_parser.py create mode 100644 projects/g-py-bigquery/project.yaml diff --git a/projects/g-py-bigquery/Dockerfile b/projects/g-py-bigquery/Dockerfile new file mode 100644 index 000000000..01d505c0d --- /dev/null +++ b/projects/g-py-bigquery/Dockerfile @@ -0,0 +1,22 @@ +# 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 pip3 install --upgrade pip && \ + pip3 install numpy ipython grpcio +RUN git clone https://github.com/googleapis/python-bigquery +COPY build.sh *.py $SRC/ +WORKDIR python-bigquery diff --git a/projects/g-py-bigquery/build.sh b/projects/g-py-bigquery/build.sh new file mode 100644 index 000000000..ab841a59e --- /dev/null +++ b/projects/g-py-bigquery/build.sh @@ -0,0 +1,23 @@ +#!/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. +# +################################################################################ + +pip3 install . + +# Build flask fuzzers +for fuzzer in $(find $SRC -name 'fuzz_*.py'); do + compile_python_fuzzer $fuzzer +done diff --git a/projects/g-py-bigquery/fuzz_parser.py b/projects/g-py-bigquery/fuzz_parser.py new file mode 100644 index 000000000..0f343a17f --- /dev/null +++ b/projects/g-py-bigquery/fuzz_parser.py @@ -0,0 +1,60 @@ +#!/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 +import IPython + +with atheris.instrument_imports(): + from google.cloud.bigquery.magics.line_arg_parser.lexer import Lexer + from google.cloud.bigquery.magics.line_arg_parser.parser import Parser + from google.cloud.bigquery.magics.line_arg_parser.parser import ParseError + from google.cloud.bigquery.magics.line_arg_parser.parser import QueryParamsParseError + +def TestOneInput(data): + fdp = atheris.FuzzedDataProvider(data) + s1 = fdp.ConsumeString(sys.maxsize) + + tokens = list(Lexer(s1)) + if len(tokens) == 0: + return + + lexer = Lexer(s1) + parser = Parser(lexer) + try: + parser.input_line() + except ParseError: + pass + + lexer = Lexer(s1) + parser = Parser(lexer) + try: + parser.collection_items() + except QueryParamsParseError: + pass + + lexer = Lexer(s1) + parser = Parser(lexer) + try: + parser.dict_items() + except QueryParamsParseError: + pass + +def main(): + atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True) + atheris.Fuzz() + +if __name__ == "__main__": + main() diff --git a/projects/g-py-bigquery/project.yaml b/projects/g-py-bigquery/project.yaml new file mode 100644 index 000000000..a2f5760d5 --- /dev/null +++ b/projects/g-py-bigquery/project.yaml @@ -0,0 +1,11 @@ +fuzzing_engines: +- libfuzzer +homepage: https://github.com/googleapis/python-bigquery +language: python +main_repo: https://github.com/googleapis/python-bigquery +sanitizers: +- address +- undefined +vendor_ccs: +- david@adalogics.com +- adam@adalogics.com