Add initial support for cargo-fuzz

This commit is contained in:
Cyryl Płotnicki 2019-02-20 20:06:55 +00:00
parent 913cba02f7
commit 9bc23dd4c6
5 changed files with 55 additions and 0 deletions

4
fuzz/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
Cargo.lock
target
corpus
artifacts

22
fuzz/Cargo.toml Normal file
View File

@ -0,0 +1,22 @@
[package]
name = "tectonic-fuzz"
version = "0.0.1"
authors = ["Automatically generated"]
publish = false
[package.metadata]
cargo-fuzz = true
[dependencies.tectonic]
path = ".."
[dependencies.libfuzzer-sys]
git = "https://github.com/rust-fuzz/libfuzzer-sys.git"
# Prevent this from interfering with workspaces
[workspace]
members = ["."]
[[bin]]
name = "compile"
path = "fuzz_targets/compile.rs"

View File

@ -0,0 +1,9 @@
#![no_main]
#[macro_use] extern crate libfuzzer_sys;
extern crate tectonic;
fuzz_target!(|data: &[u8]| {
if let Ok(data) = std::str::from_utf8(data) {
let _ = tectonic::latex_to_pdf(data);
}
});

16
fuzz/run-fuzzer.sh Executable file
View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -e
set -o pipefail
HERE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PARENT="$HERE/../"
(test -x "${HOME}/.cargo/bin/cargo-fuzz" || cargo install cargo-fuzz)
# it is important for `cargo fuzz` to be run from the project root
cd "$PARENT"
mkdir -p "$HERE/corpus"
rustup override set nightly
# run `compile` target using `seeds` as a start point and put new corpus state into `corpus` using 4 parallel jobs
cargo fuzz run compile "$HERE/corpus" "$HERE/seeds" -j 4 --all-features

4
fuzz/seeds/hello.tex Normal file
View File

@ -0,0 +1,4 @@
\documentclass{article}
\begin{document}
Hello, world!
\end{document}