From ee647d2753c561023dca030b30bfa900e882c0f3 Mon Sep 17 00:00:00 2001 From: sscobici Date: Tue, 7 Jan 2025 18:28:31 +0200 Subject: [PATCH] fuzz: add decode_aac, fix compilation errors and simplify code --- symphonia/fuzz/Cargo.toml | 6 ++++ symphonia/fuzz/fuzz_targets/decode_aac.rs | 16 +++++++++ symphonia/fuzz/fuzz_targets/decode_any.rs | 41 ++++++++++------------- symphonia/fuzz/fuzz_targets/decode_mp3.rs | 13 +++---- 4 files changed, 46 insertions(+), 30 deletions(-) create mode 100644 symphonia/fuzz/fuzz_targets/decode_aac.rs diff --git a/symphonia/fuzz/Cargo.toml b/symphonia/fuzz/Cargo.toml index 5b052045..3889c3d6 100644 --- a/symphonia/fuzz/Cargo.toml +++ b/symphonia/fuzz/Cargo.toml @@ -34,3 +34,9 @@ name = "decode_mp3" path = "fuzz_targets/decode_mp3.rs" test = false doc = false + +[[bin]] +name = "decode_aac" +path = "fuzz_targets/decode_aac.rs" +test = false +doc = false \ No newline at end of file diff --git a/symphonia/fuzz/fuzz_targets/decode_aac.rs b/symphonia/fuzz/fuzz_targets/decode_aac.rs new file mode 100644 index 00000000..7573c329 --- /dev/null +++ b/symphonia/fuzz/fuzz_targets/decode_aac.rs @@ -0,0 +1,16 @@ +#![no_main] +use libfuzzer_sys::fuzz_target; +use symphonia::core::codecs::audio::{AudioCodecParameters, AudioDecoder}; +use symphonia::core::codecs::audio::well_known::CODEC_ID_AAC; +use symphonia::core::formats::Packet; +use symphonia::default::codecs::AacDecoder; + +fuzz_target!(|data: Vec| { + let mut codec_params = AudioCodecParameters::new(); + codec_params.for_codec(CODEC_ID_AAC); + + if let Ok(mut decoder) = AacDecoder::try_new(&codec_params, &Default::default()) { + let packet = Packet::new_from_boxed_slice(0, 0, 0, data.into_boxed_slice()); + decoder.decode(&packet).ok(); + } +}); diff --git a/symphonia/fuzz/fuzz_targets/decode_any.rs b/symphonia/fuzz/fuzz_targets/decode_any.rs index 5ab24e8c..30ce4484 100644 --- a/symphonia/fuzz/fuzz_targets/decode_any.rs +++ b/symphonia/fuzz/fuzz_targets/decode_any.rs @@ -1,39 +1,32 @@ #![no_main] use libfuzzer_sys::fuzz_target; -use symphonia::core::codecs::DecoderOptions; +use symphonia::core::codecs::audio::AudioDecoderOptions; use symphonia::core::formats::FormatOptions; +use symphonia::core::formats::probe::Hint; +use symphonia::core::formats::TrackType; use symphonia::core::meta::MetadataOptions; -use symphonia::core::probe::Hint; fuzz_target!(|data: Vec| { let data = std::io::Cursor::new(data); - let source = symphonia::core::io::MediaSourceStream::new(Box::new(data), Default::default()); - - match symphonia::default::get_probe().format( + + if let Ok(mut format) = symphonia::default::get_probe().probe( &Hint::new(), source, - &FormatOptions::default(), - &MetadataOptions::default(), + FormatOptions::default(), + MetadataOptions::default(), ) { - Ok(mut probed) => { - let track = probed.format.default_track().unwrap(); - - let mut decoder = match symphonia::default::get_codecs() - .make(&track.codec_params, &DecoderOptions::default()) - { - Ok(d) => d, - Err(_) => return, - }; - - loop { - let packet = match probed.format.next_packet() { - Ok(p) => p, - Err(_) => return, - }; - let _ = decoder.decode(&packet); + if let Some(track) = format.default_track(TrackType::Audio) { + if let Some(codec_params) = track.codec_params.as_ref() { + if let Ok(mut decoder) = symphonia::default::get_codecs().make_audio_decoder( + &codec_params.audio().unwrap(), + &AudioDecoderOptions::default(), + ) { + while let Ok(Some(packet)) = format.next_packet() { + let _ = decoder.decode(&packet); + } + } } } - Err(_) => {} } }); diff --git a/symphonia/fuzz/fuzz_targets/decode_mp3.rs b/symphonia/fuzz/fuzz_targets/decode_mp3.rs index 6da0cea3..e12603d6 100644 --- a/symphonia/fuzz/fuzz_targets/decode_mp3.rs +++ b/symphonia/fuzz/fuzz_targets/decode_mp3.rs @@ -1,15 +1,16 @@ #![no_main] use libfuzzer_sys::fuzz_target; -use symphonia::core::codecs::{CODEC_ID_MP3, CodecParameters, Decoder}; +use symphonia::core::codecs::audio::{AudioCodecParameters, AudioDecoder}; +use symphonia::core::codecs::audio::well_known::CODEC_ID_MP3; use symphonia::core::formats::Packet; use symphonia::default::codecs::MpaDecoder; fuzz_target!(|data: Vec| { - let mut codec_params = CodecParameters::new(); + let mut codec_params = AudioCodecParameters::new(); codec_params.for_codec(CODEC_ID_MP3); - let mut decoder = MpaDecoder::try_new(&codec_params, &Default::default()).unwrap(); - - let packet = Packet::new_from_boxed_slice(0, 0, 0, data.into_boxed_slice()); - let _ = decoder.decode(&packet); + if let Ok(mut decoder) = MpaDecoder::try_new(&codec_params, &Default::default()) { + let packet = Packet::new_from_boxed_slice(0, 0, 0, data.into_boxed_slice()); + decoder.decode(&packet).ok(); + } });