Don't error on missing Xing/VBRI header

This commit is contained in:
Serial 2022-02-14 21:24:27 -05:00
parent 6bb0427c84
commit f9be2c8b8c
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
2 changed files with 7 additions and 11 deletions

View file

@ -195,12 +195,12 @@ impl Header {
} }
pub(crate) struct XingHeader { pub(crate) struct XingHeader {
pub frames: u32, pub(crate) frames: u32,
pub size: u32, pub(crate) size: u32,
} }
impl XingHeader { impl XingHeader {
pub(crate) fn read(reader: &mut &[u8]) -> Result<Self> { pub(crate) fn read(reader: &mut &[u8]) -> Result<Option<Self>> {
let reader_len = reader.len(); let reader_len = reader.len();
let mut header = [0; 4]; let mut header = [0; 4];
@ -230,7 +230,7 @@ impl XingHeader {
let frames = reader.read_u32::<BigEndian>()?; let frames = reader.read_u32::<BigEndian>()?;
let size = reader.read_u32::<BigEndian>()?; let size = reader.read_u32::<BigEndian>()?;
Ok(Self { frames, size }) Ok(Some(Self { frames, size }))
}, },
b"VBRI" => { b"VBRI" => {
if reader_len < 32 { if reader_len < 32 {
@ -250,13 +250,9 @@ impl XingHeader {
let size = reader.read_u32::<BigEndian>()?; let size = reader.read_u32::<BigEndian>()?;
let frames = reader.read_u32::<BigEndian>()?; let frames = reader.read_u32::<BigEndian>()?;
Ok(Self { frames, size }) Ok(Some(Self { frames, size }))
}, },
_ => Err(FileDecodingError::new( _ => Ok(None),
FileType::MP3,
"No Xing, LAME, or VBRI header located",
)
.into()),
} }
} }
} }

View file

@ -163,7 +163,7 @@ where
let mut xing_reader = [0; 32]; let mut xing_reader = [0; 32];
reader.read_exact(&mut xing_reader)?; reader.read_exact(&mut xing_reader)?;
let xing_header = XingHeader::read(&mut &xing_reader[..]).ok(); let xing_header = XingHeader::read(&mut &xing_reader[..])?;
super::properties::read_properties( super::properties::read_properties(
(first_frame_header, first_frame_offset), (first_frame_header, first_frame_offset),