Check License check for valid size instead of reading zeros

This commit is contained in:
jaby 2022-11-20 23:14:39 +01:00
parent f227ea5bec
commit 95ed64c91a
1 changed files with 8 additions and 0 deletions

View File

@ -100,6 +100,10 @@ fn process_system_area(system_area: &SystemArea, sec_writer: &mut dyn SectorWrit
fn write_license_string(sec_writer: &mut dyn SectorWriter, license_file: &mut BufferedInputFile) -> Result<(), Error> {
const LICENSE_STRING_START:u64 = 0x2488;
if license_file.get_ref().metadata()?.len() < LICENSE_STRING_START {
return Err(Error::from_str("License file to short to contain license string. Is this is a valid license file?"));
}
let mut license_string_buffer = [0u8; Mode2Form1::DATA_SIZE];
license_file.seek(SeekFrom::Start(LICENSE_STRING_START))?;
@ -119,6 +123,10 @@ fn process_system_area(system_area: &SystemArea, sec_writer: &mut dyn SectorWrit
for _ in 0..7 {
const LICENSE_SECTOR_REST:i64 = 0x120;
if license_file.get_ref().metadata()?.len() < license_file.stream_position()? + LICENSE_SECTOR_REST as u64 {
return Err(Error::from_str("License file to short to contain license logo. Is this is a valid license file?"));
}
let mut license_logo_buffer = [0u8; Mode2Form1::DATA_SIZE];
license_file.read(&mut license_logo_buffer)?;