diff --git a/Source/Core/DiscIO/CompressedBlob.cpp b/Source/Core/DiscIO/CompressedBlob.cpp index 74427c95a1..bd3a05806b 100644 --- a/Source/Core/DiscIO/CompressedBlob.cpp +++ b/Source/Core/DiscIO/CompressedBlob.cpp @@ -316,8 +316,9 @@ bool DecompressBlobToFile(const std::string& infile, const std::string& outfile, const CompressedBlobHeader &header = reader->GetHeader(); static const size_t BUFFER_BLOCKS = 32; size_t buffer_size = header.block_size * BUFFER_BLOCKS; + size_t last_buffer_size = header.block_size * (header.num_blocks % BUFFER_BLOCKS); std::vector buffer(buffer_size); - u32 num_buffers = header.num_blocks / BUFFER_BLOCKS; + u32 num_buffers = (header.num_blocks + BUFFER_BLOCKS - 1) / BUFFER_BLOCKS; int progress_monitor = std::max(1, num_buffers / 100); bool was_cancelled = false; @@ -329,8 +330,9 @@ bool DecompressBlobToFile(const std::string& infile, const std::string& outfile, if (was_cancelled) break; } - reader->Read(i * buffer_size, buffer_size, buffer.data()); - f.WriteBytes(buffer.data(), buffer_size); + const size_t sz = i == num_buffers - 1 ? last_buffer_size : buffer_size; + reader->Read(i * buffer_size, sz, buffer.data()); + f.WriteBytes(buffer.data(), sz); } if (was_cancelled)