Skip to content

Commit 4e8b543

Browse files
rilliankinetiknz
authored andcommitted
flac: Verify STREAMINFO block type and length.
This metadata block has a fixed length, so that's a better check and just verifying there's no overflow.
1 parent de242ed commit 4e8b543

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

mp4parse/tests/public.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ fn public_api() {
7676
"ES"
7777
}
7878
mp4::AudioCodecSpecific::FLACSpecificBox(flac) => {
79+
// STREAMINFO block must be present and first.
7980
assert!(flac.blocks.len() > 0);
80-
assert!(flac.blocks[0].data.len() > 0);
81+
assert!(flac.blocks[0].block_type == 0);
82+
assert!(flac.blocks[0].data.len() == 34);
8183
"FLAC"
8284
}
8385
mp4::AudioCodecSpecific::OpusSpecificBox(opus) => {

mp4parse_capi/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,12 @@ pub unsafe extern fn mp4parse_get_track_audio_info(parser: *mut mp4parse_parser,
450450
}
451451
AudioCodecSpecific::FLACSpecificBox(ref flac) => {
452452
// Return the STREAMINFO metadata block in the codec_specific.
453-
let streaminfo = &flac.blocks[0].data;
454-
if streaminfo.len() > std::u32::MAX as usize {
453+
let streaminfo = &flac.blocks[0];
454+
if streaminfo.block_type != 0 || streaminfo.data.len() != 34 {
455455
return MP4PARSE_ERROR_INVALID;
456456
}
457-
(*info).codec_specific_config.length = streaminfo.len() as u32;
458-
(*info).codec_specific_config.data = streaminfo.as_ptr();
457+
(*info).codec_specific_config.length = streaminfo.data.len() as u32;
458+
(*info).codec_specific_config.data = streaminfo.data.as_ptr();
459459
}
460460
AudioCodecSpecific::OpusSpecificBox(ref opus) => {
461461
let mut v = Vec::new();

0 commit comments

Comments
 (0)