diff options
| author | JosJuice <josjuice@gmail.com> | 2017-08-01 19:33:49 +0200 |
|---|---|---|
| committer | JosJuice <josjuice@gmail.com> | 2017-08-01 21:58:18 +0200 |
| commit | b155c46aca55b18053bc9a8a83893b87d0dcb1fb (patch) | |
| tree | 59028ee2ea41d353b4f93eec092489f90fcf3c22 /Source/Core/DiscIO/DirectoryBlob.cpp | |
| parent | 74ada98e84487a8173a2d9f53f9f66d1111086fc (diff) | |
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.
Diffstat (limited to 'Source/Core/DiscIO/DirectoryBlob.cpp')
| -rw-r--r-- | Source/Core/DiscIO/DirectoryBlob.cpp | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/Source/Core/DiscIO/DirectoryBlob.cpp b/Source/Core/DiscIO/DirectoryBlob.cpp index d4dc3c872b..696877b528 100644 --- a/Source/Core/DiscIO/DirectoryBlob.cpp +++ b/Source/Core/DiscIO/DirectoryBlob.cpp @@ -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; } |
