| 1 |
OSS-Fuzz |
| 2 |
======== |
| 3 |
|
| 4 |
Platform overview |
| 5 |
----------------- |
| 6 |
|
| 7 |
`OSS-Fuzz <https://google.github.io/oss-fuzz/>`_ is Google's free fuzzing platform for open source |
| 8 |
software. |
| 9 |
It runs librsvg's :source:`fuzz targets <fuzz>` to help |
| 10 |
detect reliability issues. |
| 11 |
|
| 12 |
Google provides public `build logs <https://oss-fuzz-build-logs.storage.googleapis.com/index.html#librsvg>`_ |
| 13 |
and `fuzzing stats <https://introspector.oss-fuzz.com/project-profile?project=librsvg>`_, 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/librsvg>`_. |
| 21 |
The ``project.yaml`` file controls who has access to bug reports and testcases. |
| 22 |
Ping the maintainer 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 librsvg's fuzzing progress. |
| 30 |
|
| 31 |
Testcases |
| 32 |
^^^^^^^^^ |
| 33 |
|
| 34 |
The dashboard contains a link to a `testcases page <https://oss-fuzz.com/testcases?project=librsvg&open=yes>`_ |
| 35 |
that lists all testcases that currently trigger a bug in librsvg. |
| 36 |
|
| 37 |
Every testcase has a dedicated page with links to view and download a minimized testcase for |
| 38 |
reproducing the failure. |
| 39 |
Each testcase page also contains a stacktrace for the failure and stats about how often the failure |
| 40 |
is encountered while fuzzing. |
| 41 |
|
| 42 |
Reproducing a failure |
| 43 |
""""""""""""""""""""" |
| 44 |
|
| 45 |
You can download a minimized testcase and run it with a local fuzz target to debug a failure on your |
| 46 |
machine. |
| 47 |
For example, to reproduce a failure with the ``render_document`` fuzz target, you can run a command |
| 48 |
like this: ``cargo fuzz run render_document minimized.svg`` |
| 49 |
|
| 50 |
Individual fuzz targets can also be run inside of a debugger for further debugging information: |
| 51 |
|
| 52 |
.. code:: bash |
| 53 |
|
| 54 |
FUZZ_TARGET=$(find ./target/*/release/ -type f -name render_document) |
| 55 |
gdb --args "$FUZZ_TARGET" minimized.svg |
| 56 |
|
| 57 |
If the failure does not reproduce locally, you can try reproducing the issue in an OSS-Fuzz |
| 58 |
container: |
| 59 |
|
| 60 |
.. code:: bash |
| 61 |
|
| 62 |
git clone https://github.com/google/oss-fuzz.git |
| 63 |
cd oss-fuzz |
| 64 |
|
| 65 |
python infra/helper.py build_image librsvg |
| 66 |
python infra/helper.py build_fuzzers librsvg |
| 67 |
python infra/helper.py reproduce librsvg render_document minimized.svg |
| 68 |
|
| 69 |
Code coverage |
| 70 |
^^^^^^^^^^^^^ |
| 71 |
|
| 72 |
The dashboard also links to code coverage data for individual fuzz targets and combined code |
| 73 |
coverage data for all targets (click on the "TOTAL COVERAGE" link for the combined data). |
| 74 |
|
| 75 |
The combined coverage data is helpful for identifying coverage gaps, insufficient corpus data, and |
| 76 |
potential candidates for future fuzz targets. |
| 77 |
|
| 78 |
Bug reports |
| 79 |
^^^^^^^^^^^ |
| 80 |
|
| 81 |
Bug reports for new failures are automatically filed in the OSS-Fuzz bug tracker with a |
| 82 |
`librsvg label <https://issues.oss-fuzz.com/issues?q=project:librsvg%20status:open>`_. |
| 83 |
Make sure you are logged in to view all existing issues. |
| 84 |
|
| 85 |
Build maintenance |
| 86 |
----------------- |
| 87 |
|
| 88 |
Google runs compiled fuzz targets on Google Compute Engine VMs. |
| 89 |
This architecture requires each project to provide a ``Dockerfile`` and ``build.sh`` script to |
| 90 |
download code, configure dependencies, compile fuzz targets, and package any corpus files. |
| 91 |
|
| 92 |
librsvg's build files can be found in the |
| 93 |
`OSS-Fuzz repo <https://github.com/google/oss-fuzz/blob/master/projects/librsvg/>`_. |
| 94 |
|
| 95 |
If dependencies change or if new fuzz targets are added, then you may need to modify the build files |
| 96 |
and build a new Docker image for OSS-Fuzz. |
| 97 |
|
| 98 |
Building an image |
| 99 |
^^^^^^^^^^^^^^^^^ |
| 100 |
|
| 101 |
Use the following commands to build librsvg's OSS-Fuzz image and fuzz targets: |
| 102 |
|
| 103 |
.. code:: bash |
| 104 |
|
| 105 |
git clone https://github.com/google/oss-fuzz.git |
| 106 |
cd oss-fuzz |
| 107 |
|
| 108 |
python infra/helper.py build_image librsvg |
| 109 |
python infra/helper.py build_fuzzers librsvg |
| 110 |
|
| 111 |
Any changes you make to the build files must be submitted as pull requests to the OSS-Fuzz repo. |
| 112 |
|
| 113 |
Debugging build failures |
| 114 |
"""""""""""""""""""""""" |
| 115 |
|
| 116 |
You can debug build failures during the ``build_fuzzers`` stage by creating a container and manually |
| 117 |
running the ``compile`` command: |
| 118 |
|
| 119 |
.. code:: bash |
| 120 |
|
| 121 |
# Create a container for building fuzz targets |
| 122 |
python infra/helper.py shell librsvg |
| 123 |
|
| 124 |
# Run this command inside the container to build the fuzz targets |
| 125 |
compile |
| 126 |
|
| 127 |
This approach is faster than re-running the ``build_fuzzers`` command, which recompiles everything |
| 128 |
from scratch each time the command is run. |
| 129 |
|
| 130 |
The ``build.sh`` script will be located at ``/src/build.sh`` inside the container. |
| 131 |
|
| 132 |
Quick links |
| 133 |
----------- |
| 134 |
|
| 135 |
* `OSS-Fuzz dashboard <https://oss-fuzz.com/>`_ |
| 136 |
* `OSS-Fuzz configuration files and build scripts for librsvg <https://github.com/google/oss-fuzz/tree/master/projects/librsvg>`_ |
| 137 |
* `All open OSS-Fuzz bugs for librsvg <https://issues.oss-fuzz.com/issues?q=project:librsvg%20status:open>`_ |
| 138 |
* `Google's OSS-Fuzz documentation <https://google.github.io/oss-fuzz/>`_ |