Merge pull request #9570 from JosJuice/wia-partial-exception-list

DiscIO: Fix reading certain WIA chunks with many exceptions
This commit is contained in:
Léo Lam 2021-03-16 11:10:12 +01:00 committed by GitHub
commit b7f931fc6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -653,7 +653,7 @@ bool WIARVZFileReader<RVZ>::Chunk::Read(u64 offset, u64 size, u8* out_ptr)
return false;
}
while (offset + size > m_out.bytes_written - m_out_bytes_used_for_exceptions)
while (offset + size > GetOutBytesWrittenExcludingExceptions())
{
u64 bytes_to_read;
if (offset + size == m_out.data.size())
@ -663,13 +663,13 @@ bool WIARVZFileReader<RVZ>::Chunk::Read(u64 offset, u64 size, u8* out_ptr)
}
else
{
// Pick a suitable amount of compressed data to read. The std::min line has to
// be as it is, but the rest is a bit arbitrary and can be changed if desired.
// Pick a suitable amount of compressed data to read. We have to ensure that bytes_to_read
// is larger than 0 and smaller than or equal to the number of bytes available to read,
// but the rest is a bit arbitrary and could be changed.
// The compressed data is probably not much bigger than the decompressed data.
// Add a few bytes for possible compression overhead and for any hash exceptions.
bytes_to_read =
offset + size - (m_out.bytes_written - m_out_bytes_used_for_exceptions) + 0x100;
bytes_to_read = offset + size - GetOutBytesWrittenExcludingExceptions() + 0x100;
// Align the access in an attempt to gain speed. But we don't actually know the
// block size of the underlying storage device, so we just use the Wii block size.
@ -839,6 +839,12 @@ void WIARVZFileReader<RVZ>::Chunk::GetHashExceptions(
m_in_bytes_used_for_exceptions));
}
template <bool RVZ>
size_t WIARVZFileReader<RVZ>::Chunk::GetOutBytesWrittenExcludingExceptions() const
{
return m_exception_lists == 0 ? m_out.bytes_written - m_out_bytes_used_for_exceptions : 0;
}
template <bool RVZ>
bool WIARVZFileReader<RVZ>::ApplyHashExceptions(
const std::vector<HashExceptionEntry>& exception_list,

View File

@ -202,6 +202,8 @@ private:
bool HandleExceptions(const u8* data, size_t bytes_allocated, size_t bytes_written,
size_t* bytes_used, bool align);
size_t GetOutBytesWrittenExcludingExceptions() const;
DecompressionBuffer m_in;
DecompressionBuffer m_out;
size_t m_in_bytes_read = 0;