mirror of
https://gitee.com/openharmony/third_party_rust_rust-base64
synced 2024-11-30 08:41:00 +00:00
Add a few fuzzers. Fixes #21
This commit is contained in:
parent
886ac99ba7
commit
c638a42687
13
README.md
13
README.md
@ -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
4
fuzz/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
target
|
||||
corpus
|
||||
artifacts
|
31
fuzz/Cargo.toml
Normal file
31
fuzz/Cargo.toml
Normal 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"
|
9
fuzz/fuzzers/roundtrip.rs
Normal file
9
fuzz/fuzzers/roundtrip.rs
Normal 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());
|
||||
});
|
9
fuzz/fuzzers/roundtrip_mime.rs
Normal file
9
fuzz/fuzzers/roundtrip_mime.rs
Normal 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());
|
||||
});
|
11
fuzz/fuzzers/roundtrip_no_pad.rs
Normal file
11
fuzz/fuzzers/roundtrip_no_pad.rs
Normal 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());
|
||||
});
|
Loading…
Reference in New Issue
Block a user