fixed GH #2723: Access violation when trying to decompress .zip file with unsupported compression method.

This commit is contained in:
Günter Obiltschnig 2019-06-23 12:42:34 +02:00
parent b782d17ced
commit 472684e13c
3 changed files with 22 additions and 1 deletions

View File

@ -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)

View File

@ -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<int>(hdr.getCompressionMethod())), fileName);
}
Poco::Path file(fileName);
file.makeFile();

View File

@ -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 <zlib.h>
#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<int>(fileEntry.getCompressionMethod())), fileEntry.getFileName());
}
}