|
| 1 | +# OSS-Fuzz integration |
| 2 | + |
| 3 | +In principle, core Markdown parsing is designed to never except/crash on any input, |
| 4 | +and so [fuzzing](https://en.wikipedia.org/wiki/Fuzzing) can be used to test this conformance. |
| 5 | +This folder contains fuzzers which are principally run downstream as part of the <https://github.com/google/oss-fuzz> infrastructure. |
| 6 | + |
| 7 | +Any file that matches `fuzz_*.py` in this repository will be built and run on OSS-Fuzz |
| 8 | +(see <https://github.com/google/oss-fuzz/blob/master/projects/markdown-it-py/build.sh>). |
| 9 | + |
| 10 | +See <https://google.github.io/oss-fuzz/advanced-topics/ideal-integration> for full details. |
| 11 | + |
| 12 | +## CI integration |
| 13 | + |
| 14 | +Fuzzing essentially runs forever, or until a crash is found, therefore it cannot be fully integrated into local continous integration testing. |
| 15 | +The workflow in `.github/workflows/fuzz.yml` though runs a brief fuzzing on code changed in a PR, |
| 16 | +which can be used to provide early warning on code changes. |
| 17 | + |
| 18 | +## Reproducing crash failures |
| 19 | + |
| 20 | +If OSS-Fuzz (or the CI workflow) identifies a crash, it will produce a "minimized testcase" file |
| 21 | +(e.g. <https://oss-fuzz.com/testcase-detail/5424112454729728>). |
| 22 | + |
| 23 | +To reproduce this crash locally, the easiest way is to run the [tox](https://tox.wiki/) environment, provided in this repository, against the test file (see `tox.ini`): |
| 24 | + |
| 25 | +``` |
| 26 | +tox -e fuzz path/to/testcase |
| 27 | +``` |
| 28 | + |
| 29 | +This idempotently sets up a local python environment with markdown-it-py (local dev) and [Atheris](https://pypi.org/project/atheris/) installed, |
| 30 | +clones <https://github.com/google/oss-fuzz> into it, |
| 31 | +and builds the fuzzers. |
| 32 | +Then the testcase is run within this environment. |
| 33 | + |
| 34 | +If you wish to simply run the full fuzzing process, |
| 35 | +you can activate this environment, then run e.g.: |
| 36 | + |
| 37 | +``` |
| 38 | +python .tox/fuzz/oss-fuzz/infra/helper.py run_fuzzer markdown-it-py fuzz_markdown |
| 39 | +``` |
| 40 | + |
| 41 | +For a more thorough guide on reproducing, see: https://google.github.io/oss-fuzz/advanced-topics/reproducing/ |
0 commit comments