WV: Fix skipping unused block content

This commit is contained in:
Serial 2024-11-20 00:23:48 -05:00 committed by Alex
parent 5e999179f5
commit f38ee26ea9

View file

@ -318,20 +318,23 @@ fn get_extended_meta_info(
} }
if size == 0 { if size == 0 {
decode_err!(@BAIL WavPack, "Encountered a zero-sized block"); // Empty blocks may not *always* be valid, but we only care about the validity
// of a few blocks.
continue;
}
if (size as usize) > reader.len() {
err!(SizeMismatch);
} }
if id & ID_FLAG_ODD_SIZE > 0 { if id & ID_FLAG_ODD_SIZE > 0 {
size -= 1; size -= 1;
} }
if (size as usize) >= reader.len() {
err!(SizeMismatch);
}
match id & 0x3F { match id & 0x3F {
ID_NON_STANDARD_SAMPLE_RATE => { ID_NON_STANDARD_SAMPLE_RATE => {
properties.sample_rate = reader.read_u24::<LittleEndian>()?; properties.sample_rate = reader.read_u24::<LittleEndian>()?;
size -= 3;
}, },
ID_DSD => { ID_DSD => {
if size <= 1 { if size <= 1 {
@ -339,6 +342,7 @@ fn get_extended_meta_info(
} }
let mut rate_multiplier = u32::from(reader.read_u8()?); let mut rate_multiplier = u32::from(reader.read_u8()?);
size -= 1;
if rate_multiplier > 30 { if rate_multiplier > 30 {
parse_mode_choice!( parse_mode_choice!(
@ -350,9 +354,6 @@ fn get_extended_meta_info(
rate_multiplier = 1 << rate_multiplier; rate_multiplier = 1 << rate_multiplier;
properties.sample_rate = properties.sample_rate.wrapping_mul(rate_multiplier); properties.sample_rate = properties.sample_rate.wrapping_mul(rate_multiplier);
// Skip DSD mode
let _ = reader.read_u8()?;
}, },
ID_MULTICHANNEL => { ID_MULTICHANNEL => {
if size <= 1 { if size <= 1 {
@ -366,18 +367,22 @@ fn get_extended_meta_info(
match s { match s {
0 => { 0 => {
let channel_mask = reader.read_u8()?; let channel_mask = reader.read_u8()?;
size -= 1;
properties.channel_mask = ChannelMask(u32::from(channel_mask)); properties.channel_mask = ChannelMask(u32::from(channel_mask));
}, },
1 => { 1 => {
let channel_mask = reader.read_u16::<LittleEndian>()?; let channel_mask = reader.read_u16::<LittleEndian>()?;
size -= 2;
properties.channel_mask = ChannelMask(u32::from(channel_mask)); properties.channel_mask = ChannelMask(u32::from(channel_mask));
}, },
2 => { 2 => {
let channel_mask = reader.read_u24::<LittleEndian>()?; let channel_mask = reader.read_u24::<LittleEndian>()?;
size -= 3;
properties.channel_mask = ChannelMask(channel_mask); properties.channel_mask = ChannelMask(channel_mask);
}, },
3 => { 3 => {
let channel_mask = reader.read_u32::<LittleEndian>()?; let channel_mask = reader.read_u32::<LittleEndian>()?;
size -= 4;
properties.channel_mask = ChannelMask(channel_mask); properties.channel_mask = ChannelMask(channel_mask);
}, },
4 => { 4 => {
@ -385,6 +390,7 @@ fn get_extended_meta_info(
properties.channels += 1; properties.channels += 1;
let channel_mask = reader.read_u24::<LittleEndian>()?; let channel_mask = reader.read_u24::<LittleEndian>()?;
size -= 4;
properties.channel_mask = ChannelMask(channel_mask); properties.channel_mask = ChannelMask(channel_mask);
}, },
@ -393,18 +399,20 @@ fn get_extended_meta_info(
properties.channels += 1; properties.channels += 1;
let channel_mask = reader.read_u32::<LittleEndian>()?; let channel_mask = reader.read_u32::<LittleEndian>()?;
size -= 5;
properties.channel_mask = ChannelMask(channel_mask); properties.channel_mask = ChannelMask(channel_mask);
}, },
_ => decode_err!(@BAIL WavPack, "Encountered invalid channel info size"), _ => decode_err!(@BAIL WavPack, "Encountered invalid channel info size"),
} }
}, },
_ => { _ => {},
let (_, rem) = reader.split_at(size as usize);
*reader = rem;
},
} }
// Skip over any remaining block size
let (_, rem) = reader.split_at(size as usize);
*reader = rem;
if id & ID_FLAG_ODD_SIZE > 0 { if id & ID_FLAG_ODD_SIZE > 0 {
let _ = reader.read_u8()?; let _ = reader.read_u8()?;
} }