Zipper: added an overflow check to make sure to produce a valid zip (next step is to implement zip64)

This commit is contained in:
emeric
2020-08-30 15:58:06 +02:00
parent 093c36f257
commit f44f7d7ca5
3 changed files with 36 additions and 7 deletions
+14
View File
@@ -176,8 +176,22 @@ namespace Zip
throw ZipperException {"Cannot get file size for '" + filePath.string() + "': " + ec.message()};
_files[filename] = std::move(fileContext);
_totalZipSize += LocalFileHeader::getHeaderSize();
_totalZipSize += filename.size();
if (fileContext.fileSize > 0)
{
_totalZipSize += fileContext.fileSize;
_totalZipSize += DataDescriptor::getHeaderSize();
_totalZipSize += CentralDirectoryHeader::getHeaderSize();
_totalZipSize += filename.size();
}
}
_totalZipSize += EndOfCentralDirectoryRecord::getHeaderSize();
if (_totalZipSize > UINT32_MAX)
throw ZipperException {"Cannot create a zip file which is larger than " + std::to_string(UINT32_MAX) + " bytes!"};
_currentFile = std::begin(_files);
}