-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add afl fuzz tests * Add reproducer binary for protobuf files Co-authored-by: Lucio Franco <[email protected]>
- Loading branch information
1 parent
c8691b7
commit 0833d46
Showing
9 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Fuzzing | ||
|
||
Prost ships a few fuzz tests, using both libfuzzer and aflfuzz. | ||
|
||
|
||
## afl | ||
|
||
To run the afl fuzz tests, first install cargo-afl: | ||
|
||
cargo install -f afl | ||
|
||
Then build a fuzz target and run afl on it: | ||
|
||
cd afl/<target>/ | ||
cargo afl build --bin fuzz-target | ||
cargo afl fuzz -i in -o out target/debug/fuzz-target | ||
|
||
To reproduce a crash: | ||
|
||
cd afl/<target>/ | ||
cargo build --bin reproduce | ||
cargo run --bin reproduce -- out/crashes/<crashfile> | ||
|
||
|
||
## libfuzzer | ||
|
||
TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
out/ | ||
core.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "fuzz-target-proto3" | ||
version = "0.1.0" | ||
authors = ["Prost developers"] | ||
edition = "2018" | ||
|
||
[[bin]] | ||
name = "fuzz-target" | ||
path = "src/main.rs" | ||
|
||
[[bin]] | ||
name = "reproduce" | ||
path = "src/reproduce.rs" | ||
|
||
[dependencies] | ||
afl = "0.4" | ||
protobuf = { path = "../../protobuf/" } | ||
tests = { path = "../../tests/" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# proto3 fuzz tests | ||
|
||
## Test corpus | ||
|
||
The test message `testmessage` was created like this: | ||
|
||
```rust | ||
use prost::Message; | ||
use protobuf::test_messages::proto3::TestAllTypesProto3; | ||
|
||
fn main() { | ||
let msg = TestAllTypesProto3 { | ||
optional_int32: 42, | ||
optional_fixed64: 9983748923, | ||
optional_bool: true, | ||
recursive_message: Some( | ||
Box::new(TestAllTypesProto3 { | ||
repeated_int32: vec![1, 2, 99, 50, -5], | ||
..Default::default() | ||
}) | ||
), | ||
repeated_sfixed32: vec![1, -1, 1, -1], | ||
repeated_float: vec![-1.0, 10.10, 1.337, std::f32::NAN], | ||
..Default::default() | ||
}; | ||
let mut buf = vec![]; | ||
msg.encode(&mut buf).unwrap(); | ||
std::fs::write("proto3-default.bin", buf).unwrap(); | ||
} | ||
``` |
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use afl::fuzz; | ||
|
||
use protobuf::test_messages::proto3::TestAllTypesProto3; | ||
use tests::roundtrip; | ||
|
||
fn main() { | ||
fuzz!(|data: &[u8]| { | ||
let _ = roundtrip::<TestAllTypesProto3>(data).unwrap_error(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use protobuf::test_messages::proto3::TestAllTypesProto3; | ||
use tests::roundtrip; | ||
|
||
fn main() { | ||
let args: Vec<String> = std::env::args().collect(); | ||
if args.len() != 2 { | ||
println!("Usage: {} <path-to-crash>", args[0]); | ||
std::process::exit(1); | ||
} | ||
|
||
let data = std::fs::read(&args[1]).expect(&format!("Could not open file {}", args[1])); | ||
let _ = roundtrip::<TestAllTypesProto3>(&data).unwrap_error(); | ||
} |