IOS/FFSP: Fix the "past EOF" check
Fixes a logic bug I introduced as part of #4942. We were not handling the "read past EOF" case correctly, which caused requested_read_length to underflow in some cases. Also fixes a comparison (though this is unlikely to change anything).
This commit is contained in:
parent
95b2b033b0
commit
b0a132875a
|
@ -209,9 +209,10 @@ IPCCommandResult FileIO::Read(const ReadWriteRequest& request)
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 requested_read_length = request.size;
|
u32 requested_read_length = request.size;
|
||||||
|
const u32 file_size = static_cast<u32>(m_file->GetSize());
|
||||||
// IOS has this check in the read request handler.
|
// IOS has this check in the read request handler.
|
||||||
if (requested_read_length + m_SeekPos > static_cast<u32>(m_file->GetSize()))
|
if (requested_read_length + m_SeekPos > file_size)
|
||||||
requested_read_length -= m_SeekPos;
|
requested_read_length = file_size - m_SeekPos;
|
||||||
|
|
||||||
DEBUG_LOG(IOS_FILEIO, "Read 0x%x bytes to 0x%08x from %s", request.size, request.buffer,
|
DEBUG_LOG(IOS_FILEIO, "Read 0x%x bytes to 0x%08x from %s", request.size, request.buffer,
|
||||||
m_name.c_str());
|
m_name.c_str());
|
||||||
|
@ -219,7 +220,7 @@ IPCCommandResult FileIO::Read(const ReadWriteRequest& request)
|
||||||
const u32 number_of_bytes_read = static_cast<u32>(
|
const u32 number_of_bytes_read = static_cast<u32>(
|
||||||
fread(Memory::GetPointer(request.buffer), 1, requested_read_length, m_file->GetHandle()));
|
fread(Memory::GetPointer(request.buffer), 1, requested_read_length, m_file->GetHandle()));
|
||||||
|
|
||||||
if (number_of_bytes_read != request.size && ferror(m_file->GetHandle()))
|
if (number_of_bytes_read != requested_read_length && ferror(m_file->GetHandle()))
|
||||||
return GetDefaultReply(FS_EACCESS);
|
return GetDefaultReply(FS_EACCESS);
|
||||||
|
|
||||||
// IOS returns the number of bytes read and adds that value to the seek position,
|
// IOS returns the number of bytes read and adds that value to the seek position,
|
||||||
|
|
Loading…
Reference in New Issue