Skip to content

Commit

Permalink
ignore unexpected eofs when checking iso magic bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
iliazeus committed Oct 14, 2024
1 parent e5e6bd6 commit d83cb25
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/iso/iso_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ impl IsoType {

fn check<R: Read + Seek>(mut reader: R, iso_type: IsoType) -> Result<bool, Error> {
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()),
}
}
}

0 comments on commit d83cb25

Please sign in to comment.