Add a few fuzzers. Fixes #21

This commit is contained in:
Marshall Pierce 2017-04-30 11:26:10 -07:00 committed by Marshall Pierce
parent 886ac99ba7
commit c638a42687
6 changed files with 77 additions and 0 deletions

View File

@ -106,6 +106,19 @@ You'll see a bunch of interleaved rust source and assembly like this. The sectio
0.00 : 106ab: je 1090e <base64::decode_config_buf::hbf68a45fefa299c1+0x46e>
```
Fuzzing
---
This uses [cargo-fuzz](https://github.com/rust-fuzz/cargo-fuzz). See `fuzz/fuzzers` for the available fuzzing scripts. To run, use an invocation like these:
```
rustup run nightly cargo fuzz run roundtrip
rustup run nightly cargo fuzz run roundtrip_no_pad
rustup run nightly cargo fuzz run roundtrip_mime -- -max_len=1024
```
License
---

4
fuzz/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
target
corpus
artifacts

31
fuzz/Cargo.toml Normal file
View File

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

View File

@ -0,0 +1,9 @@
#![no_main]
#[macro_use] extern crate libfuzzer_sys;
extern crate base64;
fuzz_target!(|data: &[u8]| {
let encoded = base64::encode_config(&data, base64::STANDARD);
let decoded = base64::decode_config(&encoded, base64::STANDARD).unwrap();
assert_eq!(data, decoded.as_slice());
});

View File

@ -0,0 +1,9 @@
#![no_main]
#[macro_use] extern crate libfuzzer_sys;
extern crate base64;
fuzz_target!(|data: &[u8]| {
let encoded = base64::encode_config(&data, base64::MIME);
let decoded = base64::decode_config(&encoded, base64::MIME).unwrap();
assert_eq!(data, decoded.as_slice());
});

View File

@ -0,0 +1,11 @@
#![no_main]
#[macro_use] extern crate libfuzzer_sys;
extern crate base64;
fuzz_target!(|data: &[u8]| {
let config = base64::Config::new(base64::CharacterSet::Standard, false, false, base64::LineWrap::NoWrap);
let encoded = base64::encode_config(&data, config);
let decoded = base64::decode_config(&encoded, config).unwrap();
assert_eq!(data, decoded.as_slice());
});