2024-04-13 16:50:28 +00:00
|
|
|
use lofty::config::ParseOptions;
|
2024-04-10 18:08:28 +00:00
|
|
|
use lofty::prelude::*;
|
|
|
|
|
2022-07-10 22:15:38 +00:00
|
|
|
use std::io::Cursor;
|
|
|
|
use std::path::Path;
|
|
|
|
use std::thread;
|
|
|
|
use std::time::Instant;
|
|
|
|
|
2024-08-24 16:45:06 +00:00
|
|
|
mod aacfile_read_from;
|
2022-07-10 22:15:38 +00:00
|
|
|
mod aifffile_read_from;
|
|
|
|
mod flacfile_read_from;
|
2024-04-03 16:30:49 +00:00
|
|
|
mod id3v2;
|
2022-07-10 22:15:38 +00:00
|
|
|
mod mp4file_read_from;
|
2024-08-24 16:40:32 +00:00
|
|
|
mod mpcfile_read_from;
|
2022-07-24 20:25:08 +00:00
|
|
|
mod mpegfile_read_from;
|
2022-07-10 22:15:38 +00:00
|
|
|
mod opusfile_read_from;
|
|
|
|
mod pictureinformation_from_jpeg;
|
|
|
|
mod pictureinformation_from_png;
|
|
|
|
mod speexfile_read_from;
|
|
|
|
mod vorbisfile_read_from;
|
|
|
|
mod wavfile_read_from;
|
|
|
|
mod wavpackfile_read_from;
|
|
|
|
|
2024-05-04 20:41:40 +00:00
|
|
|
#[allow(clippy::missing_panics_doc)]
|
2022-07-10 22:15:38 +00:00
|
|
|
pub fn get_reader(path: &str) -> Cursor<Vec<u8>> {
|
|
|
|
let path = Path::new("tests/fuzz/assets").join(path);
|
|
|
|
|
|
|
|
let b = std::fs::read(path).unwrap();
|
|
|
|
Cursor::new(b)
|
|
|
|
}
|
|
|
|
|
2024-05-04 20:41:40 +00:00
|
|
|
#[allow(clippy::missing_panics_doc)]
|
2022-07-10 22:15:38 +00:00
|
|
|
pub fn oom_test<A: AudioFile>(path: &'static str) {
|
|
|
|
let instant = Instant::now();
|
|
|
|
let thread = thread::spawn(|| {
|
2022-09-24 06:34:22 +00:00
|
|
|
let _ = <A as AudioFile>::read_from(&mut get_reader(path), ParseOptions::new());
|
2022-07-10 22:15:38 +00:00
|
|
|
});
|
|
|
|
|
2022-07-10 22:30:12 +00:00
|
|
|
while instant.elapsed().as_secs() < 3 {
|
|
|
|
if thread.is_finished() {
|
|
|
|
return;
|
|
|
|
}
|
2022-07-10 22:15:38 +00:00
|
|
|
}
|
2022-07-10 22:30:12 +00:00
|
|
|
|
|
|
|
panic!("Failed to run test");
|
2022-07-10 22:15:38 +00:00
|
|
|
}
|