mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-13 22:22:31 +00:00
Fix file signature reading
This commit is contained in:
parent
4e625f7e80
commit
b38cd09ad6
1 changed files with 20 additions and 16 deletions
|
@ -15,8 +15,6 @@ use crate::logic::ogg::vorbis::VorbisFile;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
use std::io::{Read, Seek, SeekFrom};
|
use std::io::{Read, Seek, SeekFrom};
|
||||||
|
|
||||||
use byteorder::ReadBytesExt;
|
|
||||||
|
|
||||||
/// Provides various methods for interaction with a file
|
/// Provides various methods for interaction with a file
|
||||||
pub trait AudioFile {
|
pub trait AudioFile {
|
||||||
/// Read a file from a reader
|
/// Read a file from a reader
|
||||||
|
@ -338,8 +336,7 @@ impl FileType {
|
||||||
|
|
||||||
match sig.first().unwrap() {
|
match sig.first().unwrap() {
|
||||||
77 if sig.starts_with(b"MAC") => Ok(Self::APE),
|
77 if sig.starts_with(b"MAC") => Ok(Self::APE),
|
||||||
_ if verify_frame_sync(sig[0], sig[1])
|
73 if sig.starts_with(b"ID3") => {
|
||||||
|| ((sig.starts_with(b"ID3") || sig.starts_with(b"id3")) && {
|
|
||||||
let size = decode_u32(u32::from_be_bytes(
|
let size = decode_u32(u32::from_be_bytes(
|
||||||
sig[6..10]
|
sig[6..10]
|
||||||
.try_into()
|
.try_into()
|
||||||
|
@ -348,14 +345,21 @@ impl FileType {
|
||||||
|
|
||||||
data.seek(SeekFrom::Start(u64::from(10 + size)))?;
|
data.seek(SeekFrom::Start(u64::from(10 + size)))?;
|
||||||
|
|
||||||
let b1 = data.read_u8()?;
|
let mut ident = [0; 3];
|
||||||
let b2 = data.read_u8()?;
|
data.read_exact(&mut ident)?;
|
||||||
|
|
||||||
data.seek(SeekFrom::Start(0))?;
|
data.seek(SeekFrom::Start(0))?;
|
||||||
|
|
||||||
verify_frame_sync(b1, b2)
|
if &ident == b"MAC" {
|
||||||
}) =>
|
return Ok(Self::APE);
|
||||||
{
|
} else if verify_frame_sync(ident[0], ident[1]) {
|
||||||
|
return Ok(Self::MP3);
|
||||||
|
}
|
||||||
|
|
||||||
|
Err(LoftyError::UnknownFormat)
|
||||||
|
},
|
||||||
|
_ if verify_frame_sync(sig[0], sig[1]) => {
|
||||||
|
data.seek(SeekFrom::Start(0))?;
|
||||||
Ok(Self::MP3)
|
Ok(Self::MP3)
|
||||||
},
|
},
|
||||||
70 if sig.starts_with(b"FORM") => {
|
70 if sig.starts_with(b"FORM") => {
|
||||||
|
|
Loading…
Reference in a new issue