Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add atheris fuzzer #2999

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .clusterfuzzlite/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM gcr.io/oss-fuzz-base/base-builder-python
COPY . $SRC/vyper
WORKDIR $SRC/vyper
COPY .clusterfuzzlite/build.sh $SRC/

18 changes: 18 additions & 0 deletions .clusterfuzzlite/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash -eu
pip3 install --upgrade pip
pip3 install .

for fuzzer in $(find $SRC -name 'fuzz_*.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.
this_dir=\$(dirname \"\$0\")
LD_PRELOAD=\$this_dir/sanitizer_with_fuzzer.so \
ASAN_OPTIONS=\$ASAN_OPTIONS:symbolize=1:external_symbolizer_path=\$this_dir/llvm-symbolizer:detect_leaks=0 \
\$this_dir/$fuzzer_package \$@" > $OUT/$fuzzer_basename
chmod +x $OUT/$fuzzer_basename
done
1 change: 1 addition & 0 deletions .clusterfuzzlite/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: python
29 changes: 29 additions & 0 deletions .github/workflows/cflite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: ClusterFuzzLite PR fuzzing
on:
workflow_dispatch:
pull_request:
paths:
- '**'
permissions: read-all
jobs:
PR:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
sanitizer: [address]
steps:
- name: Build Fuzzers (${{ matrix.sanitizer }})
id: build
uses: google/clusterfuzzlite/actions/build_fuzzers@v1
with:
sanitizer: ${{ matrix.sanitizer }}
language: python
- name: Run Fuzzers (${{ matrix.sanitizer }})
id: run
uses: google/clusterfuzzlite/actions/run_fuzzers@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
fuzz-seconds: 400
mode: 'code-change'
sanitizer: ${{ matrix.sanitizer }}
31 changes: 31 additions & 0 deletions tests/ast/fuzz_parse_to_ast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import sys

import atheris

with atheris.instrument_imports():
from vyper.ast import parse_to_ast
from vyper.exceptions import SyntaxException, ParserException, SyntaxException

def TestOneInput(data):
fdp = atheris.FuzzedDataProvider(data)
try:
_ = parse_to_ast(fdp.ConsumeString(len(data)))
except SyntaxException:
None
except ValueError:
None
except IndentationError:
None
except ParserException:
None
except SyntaxException:
None



def main():
atheris.Setup(sys.argv, TestOneInput, enable_python_coverage=True)
atheris.Fuzz()

if __name__ == "__main__":
main()