Fix panic in Mp4File::read_from

This commit is contained in:
Serial 2022-02-07 10:03:28 -05:00
parent d13f01d215
commit 9e18616a68
No known key found for this signature in database
GPG key ID: DA95198DC17C4568

View file

@ -2,7 +2,8 @@ use super::atom_info::{AtomIdent, AtomInfo};
use super::moov::Moov; use super::moov::Moov;
use super::properties::Mp4Properties; use super::properties::Mp4Properties;
use super::Mp4File; use super::Mp4File;
use crate::error::{ErrorKind, LoftyError, Result}; use crate::error::{ErrorKind, FileDecodingError, LoftyError, Result};
use crate::types::file::FileType;
use std::io::{Read, Seek, SeekFrom}; use std::io::{Read, Seek, SeekFrom};
@ -16,6 +17,12 @@ where
return Err(LoftyError::new(ErrorKind::UnknownFormat)); return Err(LoftyError::new(ErrorKind::UnknownFormat));
} }
// size + identifier + major brand
// There *should* be more, but this is all we need from it
if atom.len < 12 {
return Err(FileDecodingError::new(FileType::MP4, "\"ftyp\" atom too short").into());
}
let mut major_brand = vec![0; 4]; let mut major_brand = vec![0; 4];
data.read_exact(&mut major_brand)?; data.read_exact(&mut major_brand)?;