Merge pull request #2712 from JosJuice/wbfs-beyond-end-of-disc

WbfsBlob: Don't enter an infinite loop when reading beyond end of disc
This commit is contained in:
skidau 2015-07-12 15:34:56 +10:00
commit cc79334faf
1 changed files with 5 additions and 1 deletions

View File

@ -115,8 +115,10 @@ bool WbfsFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
{ {
while (nbytes) while (nbytes)
{ {
u64 read_size = 0; u64 read_size;
File::IOFile& data_file = SeekToCluster(offset, &read_size); File::IOFile& data_file = SeekToCluster(offset, &read_size);
if (read_size == 0)
return false;
read_size = (read_size > nbytes) ? nbytes : read_size; read_size = (read_size > nbytes) ? nbytes : read_size;
if (!data_file.ReadBytes(out_ptr, read_size)) if (!data_file.ReadBytes(out_ptr, read_size))
@ -160,6 +162,8 @@ File::IOFile& WbfsFileReader::SeekToCluster(u64 offset, u64* available)
} }
PanicAlert("Read beyond end of disc"); PanicAlert("Read beyond end of disc");
if (available)
*available = 0;
m_files[0]->file.Seek(0, SEEK_SET); m_files[0]->file.Seek(0, SEEK_SET);
return m_files[0]->file; return m_files[0]->file;
} }