-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add fuzzing target for sysex7 roundtrip
- Loading branch information
Ben Leadbetter
committed
May 8, 2024
1 parent
e08fbca
commit 723c565
Showing
4 changed files
with
41 additions
and
8 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,22 @@ | ||
#![no_main] | ||
|
||
use libfuzzer_sys::fuzz_target; | ||
use midi2::{prelude::*, sysex7::*}; | ||
|
||
fuzz_target!(|data: &[u8]| { | ||
let to_u7 = |b: u8| u7::new(b & 0x7F); | ||
let mut message = Sysex7::<Vec<u32>>::new(); | ||
message.set_payload(data.iter().cloned().map(to_u7)); | ||
|
||
// payload is unchanged | ||
let payload = message.payload().collect::<Vec<u7>>(); | ||
assert_eq!( | ||
payload, | ||
data.iter().cloned().map(to_u7).collect::<Vec<u7>>() | ||
); | ||
|
||
// message is in a valid state | ||
let mut buffer = Vec::new(); | ||
buffer.extend_from_slice(message.data()); | ||
let _ = Sysex7::try_from(&buffer[..]).expect("Valid data"); | ||
}); |
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