diff --git a/Zip/testsuite/data/consistency-crc32.zip b/Zip/testsuite/data/consistency-crc32.zip new file mode 100644 index 000000000..0872da562 Binary files /dev/null and b/Zip/testsuite/data/consistency-crc32.zip differ diff --git a/Zip/testsuite/data/consistency-uncompressed.zip b/Zip/testsuite/data/consistency-uncompressed.zip new file mode 100644 index 000000000..ff034f867 Binary files /dev/null and b/Zip/testsuite/data/consistency-uncompressed.zip differ diff --git a/Zip/testsuite/src/ZipTest.cpp b/Zip/testsuite/src/ZipTest.cpp index e16f3da15..d306660eb 100644 --- a/Zip/testsuite/src/ZipTest.cpp +++ b/Zip/testsuite/src/ZipTest.cpp @@ -11,6 +11,7 @@ #include "ZipTest.h" #include "Poco/Zip/SkipCallback.h" #include "Poco/Zip/ZipLocalFileHeader.h" +#include "Poco/Zip/ZipException.h" #include "Poco/Zip/ZipArchive.h" #include "Poco/Zip/ZipStream.h" #include "Poco/Zip/Decompress.h" @@ -287,6 +288,60 @@ void ZipTest::testDecompressZip64() } +void ZipTest::testDecompressConsistency() +{ + // test archives with borked file headers, but correct directory + const std::string testArchives[] = + { + "consistency-crc32.zip", + "consistency-uncompressed.zip" + }; + + + for (const std::string &archive : testArchives) + { + // + // test decompressing all files + // + { + Poco::FileInputStream inputStream(getTestFile("data", archive)); + assertTrue (inputStream.good()); + + Decompress dec(inputStream, Poco::Path::temp()); + + try { + dec.decompressAllFiles(); + assertTrue (false); + } + catch (const ZipException &e) + { + } + } + + + // + // test decompressing single file + // + { + Poco::FileInputStream inputStream(getTestFile("data", archive)); + assertTrue (inputStream.good()); + + ZipArchive archive(inputStream); + + // File decompression code is skipped since + // we are not expecting archive to be processed further + try + { + archive.checkConsistency(); + assertTrue (false); + } + catch (const ZipException &e) + { + } + } + }; +} + void ZipTest::testValidPath() { assertTrue (ZipCommon::isValidPath(".")); @@ -357,6 +412,7 @@ CppUnit::Test* ZipTest::suite() CppUnit_addTest(pSuite, ZipTest, testCrcAndSizeAfterDataEncapsulated); CppUnit_addTest(pSuite, ZipTest, testDecompressZip64); CppUnit_addTest(pSuite, ZipTest, testValidPath); + CppUnit_addTest(pSuite, ZipTest, testDecompressConsistency); return pSuite; } diff --git a/Zip/testsuite/src/ZipTest.h b/Zip/testsuite/src/ZipTest.h index cd77baaae..fa4971525 100644 --- a/Zip/testsuite/src/ZipTest.h +++ b/Zip/testsuite/src/ZipTest.h @@ -29,6 +29,7 @@ public: void testDecompressSingleFile(); void testDecompressSingleFileInDir(); void testDecompress(); + void testDecompressConsistency(); void testDecompressFlat(); void testDecompressVuln(); void testDecompressFlatVuln();