diff --git a/Source/Core/Core/Boot/DolReader.cpp b/Source/Core/Core/Boot/DolReader.cpp index 54c010013e..61b8c64213 100644 --- a/Source/Core/Core/Boot/DolReader.cpp +++ b/Source/Core/Core/Boot/DolReader.cpp @@ -32,7 +32,7 @@ DolReader::~DolReader() = default; bool DolReader::Initialize(const std::vector& buffer) { - if (buffer.size() < sizeof(SDolHeader)) + if (buffer.size() < sizeof(SDolHeader) || buffer.size() > UINT32_MAX) return false; memcpy(&m_dolheader, buffer.data(), sizeof(SDolHeader)); @@ -77,11 +77,16 @@ bool DolReader::Initialize(const std::vector& buffer) { if (m_dolheader.dataSize[i] != 0) { - if (buffer.size() < m_dolheader.dataOffset[i] + m_dolheader.dataSize[i]) + u32 section_size = m_dolheader.dataSize[i]; + u32 section_offset = m_dolheader.dataOffset[i]; + if (buffer.size() < section_offset) return false; - const u8* data_start = &buffer[m_dolheader.dataOffset[i]]; - m_data_sections.emplace_back(data_start, &data_start[m_dolheader.dataSize[i]]); + std::vector data(section_size); + const u8* data_start = &buffer[section_offset]; + std::memcpy(&data[0], data_start, + std::min((size_t)section_size, buffer.size() - section_offset)); + m_data_sections.emplace_back(data); } else {