From d83cb253794abf28f0ca397917906c4dc881e638 Mon Sep 17 00:00:00 2001 From: Ilia Pozdnyakov Date: Mon, 14 Oct 2024 11:35:45 +0500 Subject: [PATCH] ignore unexpected eofs when checking iso magic bytes --- src/iso/iso_type.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/iso/iso_type.rs b/src/iso/iso_type.rs index 9349641..4e1ab68 100644 --- a/src/iso/iso_type.rs +++ b/src/iso/iso_type.rs @@ -47,10 +47,13 @@ impl IsoType { fn check(mut reader: R, iso_type: IsoType) -> Result { let mut buf = [0_u8; 20]; - - reader.seek(SeekFrom::Start(0x20 * SECTOR_SIZE + iso_type.root_offset()))?; - reader.read_exact(&mut buf)?; - - Ok(buf == "MICROSOFT*XBOX*MEDIA".as_bytes()) + match reader + .seek(SeekFrom::Start(0x20 * SECTOR_SIZE + iso_type.root_offset())) + .and_then(|_| reader.read_exact(&mut buf)) + { + Ok(_) => Ok(&buf == b"MICROSOFT*XBOX*MEDIA"), + Err(e) if e.kind() == std::io::ErrorKind::UnexpectedEof => Ok(false), + Err(e) => Err(e.into()), + } } }