diff --git a/Zip/include/Poco/Zip/ZipLocalFileHeader.h b/Zip/include/Poco/Zip/ZipLocalFileHeader.h index 67645a2c6..736033ef4 100644 --- a/Zip/include/Poco/Zip/ZipLocalFileHeader.h +++ b/Zip/include/Poco/Zip/ZipLocalFileHeader.h @@ -190,6 +190,8 @@ private: Poco::UInt32 _crc32; Poco::UInt32 _compressedSize; Poco::UInt32 _uncompressedSize; + + friend class ZipStreamBuf; }; diff --git a/Zip/src/Compress.cpp b/Zip/src/Compress.cpp index dab372cf9..0ad0064bd 100644 --- a/Zip/src/Compress.cpp +++ b/Zip/src/Compress.cpp @@ -114,7 +114,7 @@ void Compress::addFileRaw(std::istream& in, const ZipLocalFileHeader& h, const P { Poco::Buffer buffer(COMPRESS_CHUNK_SIZE); Poco::UInt32 remaining = totalSize; - while(remaining > 0) + while (remaining > 0) { if (remaining > COMPRESS_CHUNK_SIZE) { diff --git a/Zip/src/ZipStream.cpp b/Zip/src/ZipStream.cpp index 49425c5bc..fda14ef0e 100644 --- a/Zip/src/ZipStream.cpp +++ b/Zip/src/ZipStream.cpp @@ -219,6 +219,13 @@ void ZipStreamBuf::close() _pHeader->setCRC(_crc32.checksum()); _pHeader->setUncompressedSize(_bytesWritten); _pHeader->setCompressedSize(_ptrOHelper->bytesWritten()); + if (_bytesWritten == 0) + { + poco_assert (_ptrOHelper->bytesWritten() == 0); + // Empty files must use CM_STORE, otherwise unzipping will fail + _pHeader->setCompressionMethod(ZipCommon::CM_STORE); + _pHeader->setCompressionLevel(ZipCommon::CL_NORMAL); + } _pHeader->setStartPos(_pHeader->getStartPos()); // This resets EndPos now that compressed Size is known if (_pHeader->searchCRCAndSizesAfterData()) diff --git a/Zip/src/ZipUtil.cpp b/Zip/src/ZipUtil.cpp index 1aa6d3bdc..82c3c728e 100644 --- a/Zip/src/ZipUtil.cpp +++ b/Zip/src/ZipUtil.cpp @@ -106,7 +106,7 @@ void ZipUtil::sync(std::istream& in) while (in.good() && !in.eof()) { // all zip headers start withe same 2byte prefix - if(std::memcmp(ZipLocalFileHeader::HEADER, &temp[tempPos - PREFIX], PREFIX) == 0) + if (std::memcmp(ZipLocalFileHeader::HEADER, &temp[tempPos - PREFIX], PREFIX) == 0) { // we have a possible header! // read the next 2 bytes