|
| 1 | +====================== |
| 2 | + OSS-Fuzz integration |
| 3 | +====================== |
| 4 | + |
| 5 | +Platform overview |
| 6 | +----------------- |
| 7 | + |
| 8 | +`OSS-Fuzz <https://google.github.io/oss-fuzz/>`_ is Google's free fuzzing platform for open source |
| 9 | +software. It runs astroid's fuzz targets to help detect reliability issues that could affect astroid |
| 10 | +and Pylint. |
| 11 | + |
| 12 | +Google provides public `build logs <https://oss-fuzz-build-logs.storage.googleapis.com/index.html#astroid>`_ |
| 13 | +and `fuzzing stats <https://introspector.oss-fuzz.com/project-profile?project=astroid>`_, but most |
| 14 | +of the details about bug reports and fuzzed testcases require approved access. |
| 15 | + |
| 16 | +Gaining access |
| 17 | +^^^^^^^^^^^^^^ |
| 18 | + |
| 19 | +The configuration files for the OSS-Fuzz integration can be found in the |
| 20 | +`OSS-Fuzz repository <https://github.com/google/oss-fuzz/tree/master/projects/astroid>`_. |
| 21 | +The ``project.yaml`` file controls who has access to bug reports and testcases. Ping the |
| 22 | +maintainers if you'd like to be added to the list (note: a Google account is required for |
| 23 | +access). |
| 24 | + |
| 25 | +Fuzzing progress |
| 26 | +---------------- |
| 27 | + |
| 28 | +Once you have access to OSS-Fuzz, you can log in to https://oss-fuzz.com/ with your Google account |
| 29 | +to see a dashboard of astroid's fuzzing progress. |
| 30 | + |
| 31 | +Testcases |
| 32 | +^^^^^^^^^ |
| 33 | + |
| 34 | +The dashboard contains a link to a `testcases page <https://oss-fuzz.com/testcases?project=astroid&open=yes>`_ |
| 35 | +that lists all testcases that currently trigger a bug in astroid. |
| 36 | + |
| 37 | +Every testcase has a dedicated page with links to view and download a minimized testcase for |
| 38 | +reproducing the failure. Each testcase page also contains a stacktrace for the failure and stats |
| 39 | +about how often the failure is encountered while fuzzing. |
| 40 | + |
| 41 | +Reproducing a failure |
| 42 | +""""""""""""""""""""" |
| 43 | + |
| 44 | +You can download a minimized testcase and run it locally to debug a failure on your machine. |
| 45 | +For example, to reproduce a failure with the ``fuzz_parse`` fuzz target, you can run the following |
| 46 | +commands: |
| 47 | + |
| 48 | +.. code:: bash |
| 49 | +
|
| 50 | + # Note: Atheris doesn't support Python 3.12+ yet: |
| 51 | + # https://github.com/google/atheris/issues/82 |
| 52 | + mkdir fuzzing-repro |
| 53 | + cd fuzzing-repro |
| 54 | +
|
| 55 | + pyenv install --skip-existing 3.11 |
| 56 | + pyenv shell 3.11 |
| 57 | +
|
| 58 | + python -m venv .venv-fuzzing-repro |
| 59 | + source .venv-fuzzing-repro/bin/activate |
| 60 | +
|
| 61 | + git clone https://github.com/pylint-dev/astroid.git |
| 62 | + cd astroid |
| 63 | +
|
| 64 | + pip install atheris |
| 65 | + pip install --editable . |
| 66 | +
|
| 67 | + # Save the minimized testcase as `minimized.py` in the astroid directory |
| 68 | +
|
| 69 | + cat << EOF > ./run_fuzz_parse.py |
| 70 | +
|
| 71 | + import astroid |
| 72 | + import atheris |
| 73 | +
|
| 74 | + with open('minimized.py', 'rb') as f: |
| 75 | + fdp = atheris.FuzzedDataProvider(f.read()) |
| 76 | +
|
| 77 | + code = fdp.ConsumeUnicodeNoSurrogates(fdp.ConsumeIntInRange(0, 4096)) |
| 78 | + astroid.builder.parse(code) |
| 79 | + EOF |
| 80 | +
|
| 81 | + python ./run_fuzz_parse.py |
| 82 | +
|
| 83 | +
|
| 84 | +If the failure does not reproduce locally, you can try reproducing the issue in an OSS-Fuzz |
| 85 | +container: |
| 86 | +
|
| 87 | +.. code:: bash |
| 88 | +
|
| 89 | + git clone https://github.com/google/oss-fuzz.git |
| 90 | + cd oss-fuzz |
| 91 | +
|
| 92 | + python infra/helper.py build_image astroid |
| 93 | + python infra/helper.py build_fuzzers astroid |
| 94 | + python infra/helper.py reproduce astroid fuzz_parse minimized.py |
| 95 | +
|
| 96 | +Some failures may only be reproducible in an OSS-Fuzz container because of differences in Python |
| 97 | +versions between the OSS-Fuzz platform and your local environment. |
| 98 | +
|
| 99 | +Code coverage |
| 100 | +^^^^^^^^^^^^^ |
| 101 | +
|
| 102 | +The dashboard also links to code coverage data for individual fuzz targets and combined code |
| 103 | +coverage data for all targets (click on the "TOTAL COVERAGE" link for the combined data). |
| 104 | +
|
| 105 | +The combined coverage data is helpful for identifying coverage gaps, insufficient corpus data, and |
| 106 | +potential candidates for future fuzz targets. |
| 107 | +
|
| 108 | +Bug reports |
| 109 | +^^^^^^^^^^^ |
| 110 | +
|
| 111 | +Bug reports for new failures are automatically filed in the OSS-Fuzz bug tracker with an |
| 112 | +`astroid label <https://bugs.chromium.org/p/oss-fuzz/issues/list?q=label:Proj-astroid>`_. |
| 113 | +Make sure you are logged in to view all existing issues. |
| 114 | +
|
| 115 | +Build maintenance |
| 116 | +----------------- |
| 117 | +
|
| 118 | +Google runs compiled fuzz targets on Google Compute Engine VMs. This architecture requires each |
| 119 | +project to provide a ``Dockerfile`` and ``build.sh`` script to download code, configure |
| 120 | +dependencies, compile fuzz targets, and package any corpus files. |
| 121 | +
|
| 122 | +astroid's build files and fuzz-target code can be found in the |
| 123 | +`OSS-Fuzz repo <https://github.com/google/oss-fuzz/blob/master/projects/astroid/>`_. |
| 124 | +
|
| 125 | +If dependencies change or if new fuzz targets are added, then you may need to modify the build files |
| 126 | +and build a new Docker image for OSS-Fuzz. |
| 127 | +
|
| 128 | +Building an image |
| 129 | +^^^^^^^^^^^^^^^^^ |
| 130 | +
|
| 131 | +Run the following commands to build astroid's OSS-Fuzz image and fuzz targets: |
| 132 | +
|
| 133 | +.. code:: bash |
| 134 | +
|
| 135 | + git clone https://github.com/google/oss-fuzz.git |
| 136 | + cd oss-fuzz |
| 137 | +
|
| 138 | + python infra/helper.py build_image astroid |
| 139 | + python infra/helper.py build_fuzzers astroid |
| 140 | +
|
| 141 | +Any changes you make to the build files must be submitted as pull requests to the OSS-Fuzz repo. |
| 142 | +
|
| 143 | +Debugging build failures |
| 144 | +"""""""""""""""""""""""" |
| 145 | +
|
| 146 | +You can debug build failures during the ``build_fuzzers`` stage by creating a container and manually |
| 147 | +running the ``compile`` command: |
| 148 | +
|
| 149 | +.. code:: bash |
| 150 | +
|
| 151 | + # Create a container for building fuzz targets |
| 152 | + python infra/helper.py shell astroid |
| 153 | +
|
| 154 | + # Run this command inside the container to build the fuzz targets |
| 155 | + compile |
| 156 | +
|
| 157 | +The ``build.sh`` script will be located at ``/src/build.sh`` inside the container. |
| 158 | +
|
| 159 | +Quick links |
| 160 | +----------- |
| 161 | +
|
| 162 | +- `OSS-Fuzz dashboard <https://oss-fuzz.com/>`_ |
| 163 | +- `OSS-Fuzz configuration files, build scripts, and fuzz targets for astroid <https://github.com/google/oss-fuzz/tree/master/projects/astroid>`_ |
| 164 | +- `All open OSS-Fuzz bugs for astroid <https://bugs.chromium.org/p/oss-fuzz/issues/list?q=label:Proj-astroid>`_ |
| 165 | +- `Google's OSS-Fuzz documentation <https://google.github.io/oss-fuzz/>`_ |
0 commit comments