Fix zip files made with non-seekable output. (issue #335)

This commit is contained in:
Simon Sasburg 2015-10-07 20:30:34 +01:00
parent 6fb7dd8bf7
commit ca1af32ecc
2 changed files with 9 additions and 5 deletions

View File

@ -55,6 +55,9 @@ ZipFileInfo::ZipFileInfo(const ZipLocalFileHeader& header):
setUnixAttributes();
_rawInfo[GENERAL_PURPOSE_POS+1] |= 0x08; // Set "language encoding flag" to indicate that filenames and paths are in UTF-8.
if (header.searchCRCAndSizesAfterData())
_rawInfo[GENERAL_PURPOSE_POS] |= 0x08;
}

View File

@ -218,6 +218,12 @@ void ZipStreamBuf::close(Poco::UInt64& extraDataSize)
poco_assert (*_pOstr);
// write an extra datablock if required
// or fix the crc entries
poco_check_ptr(_pHeader);
_pHeader->setCRC(_crc32.checksum());
_pHeader->setUncompressedSize(_bytesWritten);
_pHeader->setCompressedSize(_ptrOHelper->bytesWritten());
_pHeader->setStartPos(_pHeader->getStartPos()); // This resets EndPos now that compressed Size is known
if (_pHeader->searchCRCAndSizesAfterData())
{
if (_pHeader->needsZip64())
@ -241,13 +247,8 @@ void ZipStreamBuf::close(Poco::UInt64& extraDataSize)
}
else
{
poco_check_ptr (_pHeader);
_pHeader->setCRC(_crc32.checksum());
_pHeader->setUncompressedSize(_bytesWritten);
_pHeader->setCompressedSize(_ptrOHelper->bytesWritten());
_pOstr->seekp(_pHeader->getStartPos(), std::ios_base::beg);
poco_assert (*_pOstr);
_pHeader->setStartPos(_pHeader->getStartPos()); // This resets EndPos now that compressed Size is known
if (_pHeader->hasExtraField()) // Update sizes in header extension.
_pHeader->setZip64Data();
std::string header = _pHeader->createHeader();