DolReader: if data segment goes off end of file, treat it as zero-fill (bss)
This commit is contained in:
parent
4c64e18b24
commit
17498dbb4c
|
@ -32,7 +32,7 @@ DolReader::~DolReader() = default;
|
|||
|
||||
bool DolReader::Initialize(const std::vector<u8>& 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<u8>& 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<u8> 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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue