Skip to content

Commit

Permalink
fuzz: add decode_aac, fix compilation errors and simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
sscobici committed Jan 8, 2025
1 parent c3c8e7c commit ee647d2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 30 deletions.
6 changes: 6 additions & 0 deletions symphonia/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions symphonia/fuzz/fuzz_targets/decode_aac.rs
Original file line number Diff line number Diff line change
@@ -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<u8>| {
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();
}
});
41 changes: 17 additions & 24 deletions symphonia/fuzz/fuzz_targets/decode_any.rs
Original file line number Diff line number Diff line change
@@ -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<u8>| {
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(_) => {}
}
});
13 changes: 7 additions & 6 deletions symphonia/fuzz/fuzz_targets/decode_mp3.rs
Original file line number Diff line number Diff line change
@@ -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<u8>| {
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();
}
});

0 comments on commit ee647d2

Please sign in to comment.