diff options
author | Google AutoFuzz Team <security-tps@google.com> | 2020-12-11 16:30:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-11 07:30:23 -0800 |
commit | 25988ca5f165f0a8fc803ebc73e144f0ff3c4bee (patch) | |
tree | 1587e4a199600f90670ddafd22ccf4df466a1263 /projects/pygments | |
parent | 1739f320884a58a06ed0796fbdea29fbace06ba8 (diff) | |
download | oss-fuzz-25988ca5f165f0a8fc803ebc73e144f0ff3c4bee.tar.gz |
Add a fuzzer for Pygments (#4794)
* Add a fuzzer for Pygments
While pygments doesn't use native code for fuzzing,
it's the defacto solution to highlight (untrusted) code,
so unexpected exceptions and timeouts are important.
* Make the fuzzer work
* Remove a useless LD_PRELOAD
* Add a missing "main_repo" field
Diffstat (limited to 'projects/pygments')
-rw-r--r-- | projects/pygments/Dockerfile | 26 | ||||
-rw-r--r-- | projects/pygments/build.sh | 33 | ||||
-rw-r--r-- | projects/pygments/project.yaml | 12 | ||||
-rw-r--r-- | projects/pygments/pygments_fuzzer.py | 38 |
4 files changed, 109 insertions, 0 deletions
diff --git a/projects/pygments/Dockerfile b/projects/pygments/Dockerfile new file mode 100644 index 000000000..027f0d000 --- /dev/null +++ b/projects/pygments/Dockerfile @@ -0,0 +1,26 @@ +# Copyright 2019 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 git clone \ + --depth 1 \ + --branch master \ + https://github.com/pygments/pygments.git + +WORKDIR pygments + +COPY build.sh pygments_fuzzer.py $SRC/ diff --git a/projects/pygments/build.sh b/projects/pygments/build.sh new file mode 100644 index 000000000..135a17bc9 --- /dev/null +++ b/projects/pygments/build.sh @@ -0,0 +1,33 @@ +#!/bin/bash -eu +# 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. +# +################################################################################ + +# Build and install project (using current CFLAGS, CXXFLAGS). +pip3 install . + +# Build fuzzers in $OUT. +for fuzzer in $(find $SRC -name '*_fuzzer.py'); do + fuzzer_basename=$(basename -s .py $fuzzer) + fuzzer_package=${fuzzer_basename}.pkg + pyinstaller --distpath $OUT --onefile --name $fuzzer_package $fuzzer + + # Create execution wrapper. + echo "#!/bin/sh +# LLVMFuzzerTestOneInput for fuzzer detection. +ASAN_OPTIONS=\$ASAN_OPTIONS:symbolize=1:detect_leaks=0 \ +\$(dirname "\$0")/$fuzzer_package \$@" > $OUT/$fuzzer_basename + chmod u+x $OUT/$fuzzer_basename +done diff --git a/projects/pygments/project.yaml b/projects/pygments/project.yaml new file mode 100644 index 000000000..319d28818 --- /dev/null +++ b/projects/pygments/project.yaml @@ -0,0 +1,12 @@ +homepage: "https://pygments.org/" +main_repo: "https://github.com/pygments/pygments" +language: python +primary_contact: "security-tps@google.com" +auto_ccs: + - "jvoisin@google.com" + - "ipudney@google.com" +fuzzing_engines: + - libfuzzer +sanitizers: + - address + - undefined diff --git a/projects/pygments/pygments_fuzzer.py b/projects/pygments/pygments_fuzzer.py new file mode 100644 index 000000000..1f1c22870 --- /dev/null +++ b/projects/pygments/pygments_fuzzer.py @@ -0,0 +1,38 @@ +#!/usr/bin/python3 + +# Copyright 2020 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 pygments +import pygments.formatters +import pygments.lexers + + +def TestOneInput(input_bytes): + try: + lexer = pygments.lexers.guess_lexer(str(input_bytes)) + except ValueError: + return + pygments.highlight(str(input_bytes), lexer, pygments.formatters.HtmlFormatter()) + + +def main(): + atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True) + atheris.Fuzz() + + +if __name__ == "__main__": + main() |