mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-12 21:52:33 +00:00
Fix panic reading MP3 files with no MPEG frames
This commit is contained in:
parent
87315321ef
commit
89ebe2ed17
2 changed files with 24 additions and 7 deletions
|
@ -96,13 +96,6 @@ where
|
|||
// We have found the first frame
|
||||
break;
|
||||
}
|
||||
|
||||
// The search for sync bits was unsuccessful
|
||||
return Err(FileDecodingError::new(
|
||||
FileType::MP3,
|
||||
"File contains an invalid frame",
|
||||
)
|
||||
.into());
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -140,6 +133,13 @@ where
|
|||
file.last_frame_offset = reader.stream_position()?;
|
||||
|
||||
file.properties = if read_properties {
|
||||
if first_frame_header.is_none() {
|
||||
// The search for sync bits was unsuccessful
|
||||
return Err(
|
||||
FileDecodingError::new(FileType::MP3, "File contains an invalid frame").into(),
|
||||
);
|
||||
}
|
||||
|
||||
// Safe to unwrap, since we return early if no frame is found
|
||||
let first_frame_header = first_frame_header.unwrap();
|
||||
|
||||
|
@ -172,3 +172,20 @@ where
|
|||
|
||||
Ok(file)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::file::AudioFile;
|
||||
use crate::mp3::Mp3File;
|
||||
use std::fs::File;
|
||||
|
||||
#[test]
|
||||
fn issue_39() {
|
||||
// MP3 file that only consists of an ID3v2 tag
|
||||
assert!(Mp3File::read_from(
|
||||
&mut File::open("tests/files/assets/issue_39.mp3").unwrap(),
|
||||
true,
|
||||
)
|
||||
.is_err());
|
||||
}
|
||||
}
|
||||
|
|
BIN
tests/files/assets/issue_39.mp3
Normal file
BIN
tests/files/assets/issue_39.mp3
Normal file
Binary file not shown.
Loading…
Reference in a new issue