Skip to content

Commit

Permalink
feat: fuzz test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangsoledad committed Feb 15, 2019
1 parent 857b0f7 commit b888363
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 0 deletions.
3 changes: 3 additions & 0 deletions afl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

target
out
9 changes: 9 additions & 0 deletions afl/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "afl"
version = "0.1.0"
authors = ["zhangsoledad <787953403@qq.com>"]
edition = "2018"

[dependencies]
afl = "0.4"
faster-hex = "0.3"
1 change: 1 addition & 0 deletions afl/in/case1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\u{0} 𐀀G\u{0}𐀀 GG\u{0}𐀀G\u{0}Gࠀ\u{0} 𐀀 \u{0}:\u{0}\u{0}gࠀG G::GG::g𐀀G𐀀\u{0}\u{0}¡𐀀ࠀ\u{0}:GGG Gg𐀀 :\u{0}:gG ¡
1 change: 1 addition & 0 deletions afl/in/case2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ed136fFDdCcC1DbaFE8CB6Df1AdDBAea44aCcC17b0DbC2741F9CeEeaFbE7A51D
1 change: 1 addition & 0 deletions afl/in/case3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bf9E2d38aceDeeCbbAfccc4B4B7AE
1 change: 1 addition & 0 deletions afl/in/case4
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Day before yesterday I saw a rabbit, and yesterday a deer, and today, you.
13 changes: 13 additions & 0 deletions afl/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use afl::fuzz;
use faster_hex::{hex_decode, hex_encode, hex_string};

fn main() {
fuzz!(|data: &[u8]| {
let mut buffer = vec![0; data.len() * 2];
let _ = hex_encode(data, &mut buffer);
let _ = hex_string(data);
let mut dst = Vec::with_capacity(data.len());
dst.resize(data.len(), 0);
let _ = hex_decode(&buffer, &mut dst);
});
}
4 changes: 4 additions & 0 deletions fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

target
corpus
artifacts
22 changes: 22 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

[package]
name = "faster-hex-fuzz"
version = "0.0.1"
authors = ["Automatically generated"]
publish = false

[package.metadata]
cargo-fuzz = true

[dependencies.faster-hex]
path = ".."
[dependencies.libfuzzer-sys]
git = "https://github.com/rust-fuzz/libfuzzer-sys.git"

# Prevent this from interfering with workspaces
[workspace]
members = ["."]

[[bin]]
name = "faster-hex"
path = "fuzz_targets/faster-hex.rs"
14 changes: 14 additions & 0 deletions fuzz/fuzz_targets/faster-hex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![no_main]
#[macro_use] extern crate libfuzzer_sys;
extern crate faster_hex;

use faster_hex::{hex_decode, hex_encode, hex_string};

fuzz_target!(|data: &[u8]| {
let mut buffer = vec![0; data.len() * 2];
let _ = hex_encode(data, &mut buffer);
let _ = hex_string(data);
let mut dst = Vec::with_capacity(data.len());
dst.resize(data.len(), 0);
let _ = hex_decode(&buffer, &mut dst);
});

0 comments on commit b888363

Please sign in to comment.