Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions core/archive/rzip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
#include <zlib.h>

#include <cstring>
#include <new>

const u8 RZipHeader[8] = { '#', 'R', 'Z', 'I', 'P', 'v', 1, '#' };
constexpr u32 MaxChunkSize = 64_MB;

bool RZipFile::Open(hostfs::File *file, bool write)
{
Expand All @@ -45,7 +47,17 @@ bool RZipFile::Open(hostfs::File *file, bool write)
size &= 0xffffffff;
file->seek(-4, SEEK_CUR);
}
chunk = new u8[maxChunkSize];
if (maxChunkSize == 0 || maxChunkSize > MaxChunkSize)
{
file->seek(startOffset, SEEK_SET);
return false;
}
try {
chunk = new u8[maxChunkSize];
} catch (const std::bad_alloc&) {
file->seek(startOffset, SEEK_SET);
return false;
}
chunkIndex = 0;
chunkSize = 0;
}
Expand Down Expand Up @@ -114,7 +126,16 @@ size_t RZipFile::Read(void *data, size_t length)
break;
if (zippedSize == 0)
continue;
u8 *zipped = new u8[zippedSize];
const u64 maxZippedSize = (u64)maxChunkSize
+ maxChunkSize / 1000 + 12;
if (zippedSize > maxZippedSize)
break;
u8 *zipped;
try {
zipped = new u8[zippedSize];
} catch (const std::bad_alloc&) {
break;
}
if (file->read(zipped, zippedSize, 1) != 1)
{
delete [] zipped;
Expand Down
Loading