diff --git a/Zip/include/Poco/Zip/ZipLocalFileHeader.h b/Zip/include/Poco/Zip/ZipLocalFileHeader.h index 00741909c..48b07cdfb 100644 --- a/Zip/include/Poco/Zip/ZipLocalFileHeader.h +++ b/Zip/include/Poco/Zip/ZipLocalFileHeader.h @@ -85,6 +85,8 @@ public: bool isEncrypted() const; + bool hasSupportedCompressionMethod() const; + const Poco::DateTime& lastModifiedAt() const; Poco::UInt32 getCRC() const; @@ -367,6 +369,13 @@ inline bool ZipLocalFileHeader::isEncrypted() const } +inline bool ZipLocalFileHeader::hasSupportedCompressionMethod() const +{ + ZipCommon::CompressionMethod method = getCompressionMethod(); + return method == ZipCommon::CM_DEFLATE || method == ZipCommon::CM_STORE; +} + + inline void ZipLocalFileHeader::setEncryption(bool val) { if (val) diff --git a/Zip/src/Decompress.cpp b/Zip/src/Decompress.cpp index 93a2df912..8d3a60985 100644 --- a/Zip/src/Decompress.cpp +++ b/Zip/src/Decompress.cpp @@ -22,6 +22,7 @@ #include "Poco/StreamCopier.h" #include "Poco/Delegate.h" #include "Poco/FileStream.h" +#include "Poco/Format.h" namespace Poco { @@ -107,7 +108,14 @@ bool Decompress::handleZipEntry(std::istream& zipStream, const ZipLocalFileHeade } if (!ZipCommon::isValidPath(fileName)) + { throw ZipException("Illegal entry name", fileName); + } + + if (!hdr.hasSupportedCompressionMethod()) + { + throw ZipException(Poco::format("Unsupported compression method (%d)", static_cast(hdr.getCompressionMethod())), fileName); + } Poco::Path file(fileName); file.makeFile(); diff --git a/Zip/src/ZipStream.cpp b/Zip/src/ZipStream.cpp index cc2c192e6..04acb2118 100644 --- a/Zip/src/ZipStream.cpp +++ b/Zip/src/ZipStream.cpp @@ -21,6 +21,7 @@ #include "Poco/Exception.h" #include "Poco/InflatingStream.h" #include "Poco/DeflatingStream.h" +#include "Poco/Format.h" #if defined(POCO_UNBUNDLED) #include #else @@ -80,7 +81,6 @@ ZipStreamBuf::ZipStreamBuf(std::istream& istr, const ZipLocalFileHeader& fileEnt _ptrBuf = new PartialInputStream(istr, start, end, reposition); } } - else throw Poco::NotImplementedException("Unsupported compression method"); } @@ -299,6 +299,10 @@ ZipStreamBuf* ZipIOS::rdbuf() ZipInputStream::ZipInputStream(std::istream& istr, const ZipLocalFileHeader& fileEntry, bool reposition): ZipIOS(istr, fileEntry, reposition), std::istream(&_buf) { + if (!fileEntry.hasSupportedCompressionMethod()) + { + throw ZipException(Poco::format("Unsupported compression method (%d)", static_cast(fileEntry.getCompressionMethod())), fileEntry.getFileName()); + } }