From f3362ce2de59e5087f338519dc7ecb36dddab515 Mon Sep 17 00:00:00 2001 From: Jaby Date: Sun, 20 Nov 2022 23:14:39 +0100 Subject: [PATCH] Check License check for valid size instead of reading zeros --- src/Tools/psxcdgen_ex/src/encoder/psx.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Tools/psxcdgen_ex/src/encoder/psx.rs b/src/Tools/psxcdgen_ex/src/encoder/psx.rs index cd4841e1..884bd89f 100644 --- a/src/Tools/psxcdgen_ex/src/encoder/psx.rs +++ b/src/Tools/psxcdgen_ex/src/encoder/psx.rs @@ -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)?;