Fix unzip max buffer length error
parent
c464d01778
commit
895137c7d7
|
@ -217,10 +217,25 @@ ZipFile *ZipFileInfo::Extract(unzFile zip_handle) const {
|
||||||
|
|
||||||
ZipFile *zip_file = new ZipFile(m_Size);
|
ZipFile *zip_file = new ZipFile(m_Size);
|
||||||
|
|
||||||
if (unzReadCurrentFile(zip_handle, zip_file->m_Buffer.get(), static_cast<unsigned int>(m_Size)) != static_cast<int>(m_Size)) {
|
// Unzip has a limit of UINT16_MAX bytes buffer
|
||||||
// Failed, release the memory
|
std::unique_ptr<uint8_t[]> unzipBuffer = std::unique_ptr<uint8_t[]>(new uint8_t[UINT16_MAX]);
|
||||||
delete zip_file;
|
size_t readCount = 0;
|
||||||
zip_file = nullptr;
|
while (readCount < zip_file->m_Size) {
|
||||||
|
size_t bufferSize = zip_file->m_Size - readCount;
|
||||||
|
if (bufferSize > UINT16_MAX) {
|
||||||
|
bufferSize = UINT16_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = unzReadCurrentFile(zip_handle, unzipBuffer.get(), static_cast<unsigned int>(bufferSize));
|
||||||
|
if (ret != static_cast<int>(bufferSize)) {
|
||||||
|
// Failed, release the memory
|
||||||
|
delete zip_file;
|
||||||
|
zip_file = nullptr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::memcpy(zip_file->m_Buffer.get() + readCount, unzipBuffer.get(), ret);
|
||||||
|
readCount += ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ai_assert(unzCloseCurrentFile(zip_handle) == UNZ_OK);
|
ai_assert(unzCloseCurrentFile(zip_handle) == UNZ_OK);
|
||||||
|
|
Loading…
Reference in New Issue