From ac3055d71f93ac375c46753813fef62ba1465acc Mon Sep 17 00:00:00 2001 From: DavidKorczynski Date: Tue, 3 Jan 2023 16:52:23 +0000 Subject: [PATCH] networkx: initial integration (#9342) Signed-off-by: David Korczynski Signed-off-by: David Korczynski --- projects/networkx/Dockerfile | 19 +++++++++++++++ projects/networkx/build.sh | 24 +++++++++++++++++++ projects/networkx/fuzz_graph6.py | 38 +++++++++++++++++++++++++++++ projects/networkx/fuzz_graphml.py | 40 +++++++++++++++++++++++++++++++ projects/networkx/fuzz_sparse6.py | 39 ++++++++++++++++++++++++++++++ projects/networkx/project.yaml | 10 ++++++++ 6 files changed, 170 insertions(+) create mode 100644 projects/networkx/Dockerfile create mode 100644 projects/networkx/build.sh create mode 100644 projects/networkx/fuzz_graph6.py create mode 100644 projects/networkx/fuzz_graphml.py create mode 100644 projects/networkx/fuzz_sparse6.py create mode 100644 projects/networkx/project.yaml diff --git a/projects/networkx/Dockerfile b/projects/networkx/Dockerfile new file mode 100644 index 000000000..f9f6fef59 --- /dev/null +++ b/projects/networkx/Dockerfile @@ -0,0 +1,19 @@ +#!/usr/bin/python3 +# Copyright 2023 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/networkx/networkx networkx +RUN git clone --depth=1 https://github.com/prefuse/Prefuse prefuse +COPY *.sh *py $SRC/ +WORKDIR $SRC/networkx diff --git a/projects/networkx/build.sh b/projects/networkx/build.sh new file mode 100644 index 000000000..b0f36acdf --- /dev/null +++ b/projects/networkx/build.sh @@ -0,0 +1,24 @@ +#!/bin/bash -eu +# Copyright 2023 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 fuzzers in $OUT. +for fuzzer in $(find $SRC -name 'fuzz_*.py'); do + compile_python_fuzzer $fuzzer +done + +zip -jr $OUT/fuzz_graphml_seed_corpus.zip $SRC/prefuse/data/*.xml diff --git a/projects/networkx/fuzz_graph6.py b/projects/networkx/fuzz_graph6.py new file mode 100644 index 000000000..2137b4d43 --- /dev/null +++ b/projects/networkx/fuzz_graph6.py @@ -0,0 +1,38 @@ +#!/usr/bin/python3 +# Copyright 2023 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 sys +import atheris +import networkx + + +def TestOneInput(data): + if len(data) < 5: + return + try: + networkx.from_graph6_bytes(data) + except networkx.NetworkXError: + pass + except ValueError: + pass + + +def main(): + atheris.instrument_all() + atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True) + atheris.Fuzz() + + +if __name__ == "__main__": + main() diff --git a/projects/networkx/fuzz_graphml.py b/projects/networkx/fuzz_graphml.py new file mode 100644 index 000000000..cc3c1d0ef --- /dev/null +++ b/projects/networkx/fuzz_graphml.py @@ -0,0 +1,40 @@ +#!/usr/bin/python3 +# Copyright 2023 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 sys +import atheris +import networkx +import io +import xml + +def TestOneInput(data): + try: + networkx.read_graphml(io.BytesIO(data)) + except xml.etree.ElementTree.ParseError: + pass + except networkx.NetworkXError: + pass + except LookupError: + pass + except ValueError: + pass + +def main(): + atheris.instrument_all() + atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True) + atheris.Fuzz() + + +if __name__ == "__main__": + main() diff --git a/projects/networkx/fuzz_sparse6.py b/projects/networkx/fuzz_sparse6.py new file mode 100644 index 000000000..45d9fd910 --- /dev/null +++ b/projects/networkx/fuzz_sparse6.py @@ -0,0 +1,39 @@ +#!/usr/bin/python3 +# Copyright 2023 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 sys +import atheris +import networkx + + +def TestOneInput(data): + if len(data) < 5: + return + + try: + networkx.from_sparse6_bytes(data) + except networkx.NetworkXError: + pass + except ValueError: + pass + + +def main(): + atheris.instrument_all() + atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True) + atheris.Fuzz() + + +if __name__ == "__main__": + main() diff --git a/projects/networkx/project.yaml b/projects/networkx/project.yaml new file mode 100644 index 000000000..127c606c3 --- /dev/null +++ b/projects/networkx/project.yaml @@ -0,0 +1,10 @@ +fuzzing_engines: +- libfuzzer +homepage: https://github.com/networkx/networkx +language: python +main_repo: https://github.com/networkx/networkx +sanitizers: +- address +- undefined +vendor_ccs: +- david@adalogics.com