Skip to content

Commit

Permalink
fix fuzzers
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallpierce committed Nov 29, 2022
1 parent 0996b81 commit 604a3ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 5 additions & 2 deletions fuzz/fuzzers/roundtrip_no_pad.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#![no_main]
#[macro_use] extern crate libfuzzer_sys;
#[macro_use]
extern crate libfuzzer_sys;
extern crate base64;

use base64::engine::fast_portable;

fuzz_target!(|data: &[u8]| {
let config = fast_portable::FastPortableConfig::new().with_encode_padding(false);
let config = fast_portable::FastPortableConfig::new()
.with_encode_padding(false)
.with_decode_padding_mode(fast_portable::DecodePaddingMode::RequireNone);
let engine = fast_portable::FastPortable::from(&base64::alphabet::STANDARD, config);

let encoded = base64::encode_engine(&data, &engine);
Expand Down
11 changes: 9 additions & 2 deletions fuzz/fuzzers/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ pub fn random_engine(data: &[u8]) -> fast_portable::FastPortable {
alphabet::STANDARD
};

let encode_padding = rng.gen();
let decode_padding = if encode_padding {
fast_portable::DecodePaddingMode::RequireCanonical
} else {
fast_portable::DecodePaddingMode::RequireNone
};
let config = fast_portable::FastPortableConfig::new()
.with_encode_padding(rng.gen())
.with_decode_allow_trailing_bits(rng.gen());
.with_encode_padding(encode_padding)
.with_decode_allow_trailing_bits(rng.gen())
.with_decode_padding_mode(decode_padding);

fast_portable::FastPortable::from(&alphabet, config)
}

0 comments on commit 604a3ca

Please sign in to comment.