minor fixes

This commit is contained in:
Günter Obiltschnig 2017-11-02 09:17:29 +01:00
parent b09b32a3de
commit 2b95e4d2ee
5 changed files with 14 additions and 9 deletions

View File

@ -31,7 +31,7 @@ class Zip_API ZipCommon
public: public:
enum enum
{ {
HEADER_SIZE = 4, HEADER_SIZE = 4
}; };
static const Poco::UInt16 ZIP64_EXTRA_ID = 0x1; // Extra data id tag for Zip64 data (in extension for ZipLocalFileHeader and ZipFileInfo) static const Poco::UInt16 ZIP64_EXTRA_ID = 0x1; // Extra data id tag for Zip64 data (in extension for ZipLocalFileHeader and ZipFileInfo)

View File

@ -213,7 +213,6 @@ private:
}; };
inline Poco::UInt32 ZipFileInfo::getCRCFromHeader() const inline Poco::UInt32 ZipFileInfo::getCRCFromHeader() const
{ {
return ZipUtil::get32BitValue(_rawInfo, CRC32_POS); return ZipUtil::get32BitValue(_rawInfo, CRC32_POS);

View File

@ -80,7 +80,7 @@ bool Decompress::handleZipEntry(std::istream& zipStream, const ZipLocalFileHeade
{ {
std::string dirName = hdr.getFileName(); std::string dirName = hdr.getFileName();
if (!ZipCommon::isValidPath(dirName)) if (!ZipCommon::isValidPath(dirName))
throw ZipException("Illegal entry name " + dirName); throw ZipException("Illegal entry name", dirName);
Poco::Path dir(_outDir, dirName); Poco::Path dir(_outDir, dirName);
dir.makeDirectory(); dir.makeDirectory();
Poco::File aFile(dir); Poco::File aFile(dir);
@ -100,7 +100,7 @@ bool Decompress::handleZipEntry(std::istream& zipStream, const ZipLocalFileHeade
} }
if (!ZipCommon::isValidPath(fileName)) if (!ZipCommon::isValidPath(fileName))
throw ZipException("Illegal entry name " + fileName); throw ZipException("Illegal entry name", fileName);
Poco::Path file(fileName); Poco::Path file(fileName);
file.makeFile(); file.makeFile();

View File

@ -22,9 +22,16 @@ namespace Zip {
bool ZipCommon::isValidPath(const std::string& path) bool ZipCommon::isValidPath(const std::string& path)
{ {
try
if (!Path(path).isRelative() || !Path(path, Path::PATH_WINDOWS).isRelative()) {
if (Path(path, Path::PATH_UNIX).isAbsolute() || Path(path, Path::PATH_WINDOWS).isAbsolute())
return false; return false;
}
catch (...)
{
return false;
}
if (path == "..") if (path == "..")
return false; return false;
if ((path.size() >= 3) && path.compare(0, 3, "../") == 0) if ((path.size() >= 3) && path.compare(0, 3, "../") == 0)
@ -41,8 +48,7 @@ bool ZipCommon::isValidPath(const std::string& path)
return false; return false;
if ((path.size() >= 2) && path.compare(0, 2, "~/") == 0) if ((path.size() >= 2) && path.compare(0, 2, "~/") == 0)
return false; return false;
if (path.size() > 0 && (path[0] == '/' || path[0] == '\\'))
return false;
return true; return true;
} }

View File

@ -11,6 +11,6 @@ objects = ZipTestSuite Driver \
target = testrunner target = testrunner
target_version = 1 target_version = 1
target_libs = PocoZip PocoNet PocoFoundation PocoCppUnit target_libs = PocoZip PocoFoundation PocoCppUnit
include $(POCO_BASE)/build/rules/exec include $(POCO_BASE)/build/rules/exec