DirectoryBlob: Fix reading beyond the end of the disc
There were two problems with this: 1. If the starting offset was beyond the end of the disc, we would dereference an invalid iterator. 2. The data beyond the end of the disc was non-deterministic.
This commit is contained in:
parent
74ada98e84
commit
b155c46aca
|
@ -151,23 +151,21 @@ bool DiscContentContainer::Read(u64 offset, u64 length, u8* buffer) const
|
|||
// Determine which DiscContent the offset refers to
|
||||
std::set<DiscContent>::const_iterator it = m_contents.upper_bound(DiscContent(offset));
|
||||
|
||||
// zero fill to start of file data
|
||||
PadToAddress(it->GetOffset(), &offset, &length, &buffer);
|
||||
|
||||
while (it != m_contents.end() && length > 0)
|
||||
{
|
||||
// Zero fill to start of DiscContent data
|
||||
PadToAddress(it->GetOffset(), &offset, &length, &buffer);
|
||||
|
||||
if (!it->Read(&offset, &length, &buffer))
|
||||
return false;
|
||||
|
||||
++it;
|
||||
|
||||
if (it != m_contents.end())
|
||||
{
|
||||
_dbg_assert_(DISCIO, it->GetOffset() >= offset);
|
||||
PadToAddress(it->GetOffset(), &offset, &length, &buffer);
|
||||
}
|
||||
_dbg_assert_(DISCIO, it == m_contents.end() || it->GetOffset() >= offset);
|
||||
}
|
||||
|
||||
// Zero fill if we went beyond the last DiscContent
|
||||
std::fill_n(buffer, static_cast<size_t>(length), 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue