Skip to content

Commit

Permalink
Add simple fuzzing
Browse files Browse the repository at this point in the history
Add infrastructure to automatically run fuzzers in CI,
and implement a simple fuzzing test based on triggering all (most)
public APIs in a randimized way.

As far as I was able to try it catches the previous unsoundness issues
in a matter of seconds. This can be tried by changing the `path = "../"` dependency to
`version = "=0.6.3"` etc. and running the fuzzer manually. (Note: You'll need
to tweak the `Cargo.lock` to allow downloading the yanked versions).

Related to #124
  • Loading branch information
dpc committed Oct 30, 2019
1 parent b2c9c65 commit 85c54a5
Show file tree
Hide file tree
Showing 7 changed files with 521 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
target
Cargo.lock
./Cargo.lock
34 changes: 28 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
language: rust
rust:
- 1.36.0
- nightly
- beta
- stable
addons:
apt:
update: true
packages:
- binutils-dev
- libunwind8-dev
- libcurl4-openssl-dev
- libelf-dev
- libdw-dev
- cmake
- gcc
- libiberty-dev
matrix:
include:
- rust: 1.36.0
- rust: nightly
- rust: beta
env: DO_FUZZ=true
- rust: stable
env: DO_FUZZ=true
script: |
cargo build --verbose &&
cargo test --verbose &&
Expand All @@ -12,4 +27,11 @@ script: |
([ $TRAVIS_RUST_VERSION != nightly ] || cargo test --verbose --features union) &&
([ $TRAVIS_RUST_VERSION != nightly ] || cargo test --verbose --all-features) &&
([ $TRAVIS_RUST_VERSION != nightly ] || cargo bench --verbose bench) &&
([ $TRAVIS_RUST_VERSION != nightly ] || bash ./scripts/run_miri.sh)
([ $TRAVIS_RUST_VERSION != nightly ] || bash ./scripts/run_miri.sh) &&
if [ "$DO_FUZZ" = true ]
then
(
cd fuzz
./travis-fuzz.sh
)
fi
192 changes: 192 additions & 0 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "smallvec-fuzz"
version = "0.1.0"
authors = ["Dawid Ciężarkiewicz <dpc@dpc.pw>"]
edition = "2018"
publish = false

[package.metadata]
cargo-fuzz = true

[features]
afl_fuzz = ["afl"]
honggfuzz_fuzz = ["honggfuzz"]


[dependencies]
honggfuzz = { version = "0.5.45", optional = true }
afl = { version = "0.4", optional = true }
smallvec = { path = ".." }

[workspace]
members = ["."]

[[bin]]
name = "smallvec_ops"
path = "fuzz_targets/smallvec_ops.rs"
12 changes: 12 additions & 0 deletions fuzz/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Fuzzer for smallvec

Based on fuzzing in [rust-bitcoin](https://github.com/rust-bitcoin/rust-bitcoin/tree/c8ac25219a09bf9d017f1b05abe3e746e2136f73/fuzz)

## Running manually with afl

```
cargo afl build --release --bin smallvec_ops --features afl && cargo afl fuzz -i in -o out target/release/smallvec_ops
```

# Useful links:
* https://rust-fuzz.github.io/book/afl.html
Loading

0 comments on commit 85c54a5

Please sign in to comment.