diff --git a/src/mp3/read.rs b/src/mp3/read.rs index 2e226574..db1f650f 100644 --- a/src/mp3/read.rs +++ b/src/mp3/read.rs @@ -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()); + } +} diff --git a/tests/files/assets/issue_39.mp3 b/tests/files/assets/issue_39.mp3 new file mode 100644 index 00000000..dfa9d885 Binary files /dev/null and b/tests/files/assets/issue_39.mp3 differ