mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-11-14 00:17:07 +00:00
Fix panic
This commit is contained in:
parent
52869915b7
commit
6670ea9cd5
1 changed files with 13 additions and 17 deletions
|
@ -305,7 +305,7 @@ impl FileType {
|
||||||
match Self::quick_type_guess(buf) {
|
match Self::quick_type_guess(buf) {
|
||||||
Some(f_ty) => Ok((Some(f_ty), 0)),
|
Some(f_ty) => Ok((Some(f_ty), 0)),
|
||||||
// Special case for ID3, gets checked in `Probe::guess_file_type`
|
// Special case for ID3, gets checked in `Probe::guess_file_type`
|
||||||
None if buf.starts_with(b"ID3") && buf.len() >= 11 => {
|
None if buf.len() >= 11 && &buf[..3] == b"ID3" => {
|
||||||
let size = unsynch_u32(u32::from_be_bytes(
|
let size = unsynch_u32(u32::from_be_bytes(
|
||||||
buf[6..10]
|
buf[6..10]
|
||||||
.try_into()
|
.try_into()
|
||||||
|
@ -323,32 +323,28 @@ impl FileType {
|
||||||
|
|
||||||
match buf.first().unwrap() {
|
match buf.first().unwrap() {
|
||||||
77 if buf.starts_with(b"MAC") => Some(Self::APE),
|
77 if buf.starts_with(b"MAC") => Some(Self::APE),
|
||||||
_ if verify_frame_sync([buf[0], buf[1]]) => Some(Self::MP3),
|
255 if buf.len() >= 2 && verify_frame_sync([buf[0], buf[1]]) => Some(Self::MP3),
|
||||||
70 if buf.starts_with(b"FORM") => {
|
70 if buf.len() >= 12 && &buf[..4] == b"FORM" => {
|
||||||
if buf.len() >= 12 {
|
let id = &buf[8..12];
|
||||||
let id = &[buf[8], buf[9], buf[10], buf[11]];
|
|
||||||
|
|
||||||
if id == b"AIFF" || id == b"AIFC" {
|
if id == b"AIFF" || id == b"AIFC" {
|
||||||
return Some(Self::AIFF);
|
return Some(Self::AIFF);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
79 if buf.starts_with(b"OggS") => {
|
79 if buf.len() >= 36 && &buf[..4] == b"OggS" => {
|
||||||
if buf.len() >= 36 {
|
if &buf[29..35] == b"vorbis" {
|
||||||
if &buf[29..35] == b"vorbis" {
|
return Some(Self::Vorbis);
|
||||||
return Some(Self::Vorbis);
|
} else if &buf[28..36] == b"OpusHead" {
|
||||||
} else if &buf[28..36] == b"OpusHead" {
|
return Some(Self::Opus);
|
||||||
return Some(Self::Opus);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
102 if buf.starts_with(b"fLaC") => Some(Self::FLAC),
|
102 if buf.starts_with(b"fLaC") => Some(Self::FLAC),
|
||||||
82 if buf.starts_with(b"RIFF") => {
|
82 if buf.len() >= 12 && &buf[..4] == b"RIFF" => {
|
||||||
if buf.len() >= 12 && &buf[8..12] == b"WAVE" {
|
if &buf[8..12] == b"WAVE" {
|
||||||
return Some(Self::WAV);
|
return Some(Self::WAV);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue