From 9018b546c71932a46a85222a3de7a989184361ec Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 6 Jul 2015 15:41:37 +0200 Subject: [PATCH] WbfsBlob: Don't enter an infinite loop when reading beyond end of disc read_size remained 0 when the "Read beyond end of disc" error occurs, which made the while (nbytes) loop never end. As a fix, SeekToCluster now explicitly sets available to 0 when the error occurs, and Read checks for it. --- Source/Core/DiscIO/WbfsBlob.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Core/DiscIO/WbfsBlob.cpp b/Source/Core/DiscIO/WbfsBlob.cpp index ef90026621..5c0ac028ea 100644 --- a/Source/Core/DiscIO/WbfsBlob.cpp +++ b/Source/Core/DiscIO/WbfsBlob.cpp @@ -115,8 +115,10 @@ bool WbfsFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr) { while (nbytes) { - u64 read_size = 0; + u64 read_size; File::IOFile& data_file = SeekToCluster(offset, &read_size); + if (read_size == 0) + return false; read_size = (read_size > nbytes) ? nbytes : 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"); + if (available) + *available = 0; m_files[0]->file.Seek(0, SEEK_SET); return m_files[0]->file; }