| 1 | # Fuzzing with cargo-fuzz |
| 2 | |
| 3 | ======================= |
| 4 | |
| 5 | * `cargo install cargo-fuzz` |
| 6 | |
| 7 | * `rustup default nightly` - cargo-fuzz requires the nightly compiler, |
| 8 | unfortunately. |
| 9 | |
| 10 | * `cargo fuzz run render_document` |
| 11 | |
| 12 | ## Configuring fuzzer runs |
| 13 | |
| 14 | To pass options to the fuzzer, do it after `--`, for example: |
| 15 | |
| 16 | ```sh |
| 17 | cargo fuzz run render_document -- -seed_inputs=corpus1.svg,corpus2.svg,corpus3.svg -only_ascii=1 |
| 18 | ``` |
| 19 | |
| 20 | To get a list of available options, `cargo fuzz run render_document -- -help=1` |
| 21 | |
| 22 | ### Using dictionaries |
| 23 | |
| 24 | There are existing SVG, XML, and CSS dictionaries that can be used with fuzz |
| 25 | targets: |
| 26 | |
| 27 | ```sh |
| 28 | curl https://raw.githubusercontent.com/google/fuzzing/master/dictionaries/{css,svg,xml}.dict > combined.dict |
| 29 | |
| 30 | cargo fuzz run render_document corpus/ -- -dict=combined.dict |
| 31 | ``` |
| 32 | |
| 33 | ## Reproducing a failure |
| 34 | |
| 35 | You can reproduce a failure by supplying a path to the fuzzed data: |
| 36 | |
| 37 | `cargo fuzz run render_document fuzzed.svg` |
| 38 | |
| 39 | Fuzz targets can also be run inside of a debugger for further debugging |
| 40 | information: |
| 41 | |
| 42 | ```bash |
| 43 | FUZZ_TARGET=$(find ./target/*/release/ -type f -name render_document) |
| 44 | gdb --args "$FUZZ_TARGET" fuzzed.svg |
| 45 | ``` |
| 46 | |
| 47 | ## Suppressing leak reports |
| 48 | |
| 49 | You can suppress spurious leak reports by specifying a suppressions file via the |
| 50 | `LSAN_OPTIONS` environment variable: |
| 51 | |
| 52 | ```bash |
| 53 | LSAN_OPTIONS="suppressions=../tools/lsan.supp" cargo fuzz run render_document fuzzed.svg |
| 54 | ``` |
| 55 | |
| 56 | ## Related documents |
| 57 | |
| 58 | See `../afl-fuzz/README.md` for a to-do list for people who want to help with |
| 59 | fuzzing. |
| 60 | |
| 61 | See `../devel-docs/oss_fuzz.rst` for an overview of librsvg's integration with |
| 62 | OSS-Fuzz. |