Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #67 from jordan-woyak/master
Fixed issue 7020. CISO >4GB failure. Caused by integer overflow.
  • Loading branch information
Parlane committed Feb 13, 2014
2 parents 06329e2 + d6f6672 commit 8e50675
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions Source/Core/DiscIO/CISOBlob.cpp
Expand Up @@ -24,7 +24,7 @@ CISOFileReader::CISOFileReader(std::FILE* file)
m_block_size = header.block_size;

MapType count = 0;
for (u32 idx = 0; idx < CISO_MAP_SIZE; idx++)
for (u32 idx = 0; idx < CISO_MAP_SIZE; ++idx)
m_ciso_map[idx] = (1 == header.map[idx]) ? count++ : UNUSED_BLOCK_ID;
}

Expand Down Expand Up @@ -53,29 +53,26 @@ bool CISOFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
{
while (nbytes != 0)
{
auto const block = offset / m_block_size;
auto const data_offset = offset % m_block_size;
u64 const block = offset / m_block_size;
u64 const data_offset = offset % m_block_size;
u64 const bytes_to_read = std::min(m_block_size - data_offset, nbytes);

auto const bytes_to_read = std::min(m_block_size - data_offset, nbytes);
if (block < CISO_MAP_SIZE && UNUSED_BLOCK_ID != m_ciso_map[block])
{
// calculate the base address
auto const file_off = CISO_HEADER_SIZE + m_ciso_map[block] * m_block_size + data_offset;
u64 const file_off = CISO_HEADER_SIZE + m_ciso_map[block] * (u64)m_block_size + data_offset;

if (!(m_file.Seek(file_off, SEEK_SET) && m_file.ReadArray(out_ptr, bytes_to_read)))
return false;

out_ptr += bytes_to_read;
offset += bytes_to_read;
nbytes -= bytes_to_read;
}
else
{
std::fill_n(out_ptr, bytes_to_read, 0);
out_ptr += bytes_to_read;
offset += bytes_to_read;
nbytes -= bytes_to_read;
}

out_ptr += bytes_to_read;
offset += bytes_to_read;
nbytes -= bytes_to_read;
}

return true;
Expand Down

0 comments on commit 8e50675

Please sign in to comment.