diff --git a/package/qa/cppunit/data/tdf163364.ods b/package/qa/cppunit/data/tdf163364.ods new file mode 100644 index 000000000000..a772aebdbc7e Binary files /dev/null and b/package/qa/cppunit/data/tdf163364.ods differ diff --git a/package/qa/cppunit/test_zippackage.cxx b/package/qa/cppunit/test_zippackage.cxx index 624457ab7bcf..892f2979cd61 100644 --- a/package/qa/cppunit/test_zippackage.cxx +++ b/package/qa/cppunit/test_zippackage.cxx @@ -384,6 +384,34 @@ CPPUNIT_TEST_FIXTURE(ZipPackageTest, testZip64End) } } +CPPUNIT_TEST_FIXTURE(ZipPackageTest, testTdf163364) +{ + auto const url(m_directories.getURLFromSrc(u"/package/qa/cppunit/data/tdf163364.ods")); + uno::Sequence const args{ + uno::Any(url), + uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::PACKAGE))) + }; + + // don't load corrupted zip file + CPPUNIT_ASSERT_THROW(m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext( + ZipPackage, args, m_xContext), + css::packages::zip::ZipIOException); + + try + { + uno::Sequence const args2{ + uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))), + uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP))) + }; + m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args2, + m_xContext); + } + catch (css::packages::zip::ZipIOException const&) + { + // check that this doesn't crash, it doesn't matter if it succeeds or not + } +} + //CPPUNIT_TEST_SUITE_REGISTRATION(...); //CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index 0ddc0906e02a..371f37807be9 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -192,6 +192,14 @@ void ZipPackage::checkZipEntriesWithDD() { uno::Reference xStream; getByHierarchicalName(rEntry.sPath) >>= xStream; + uno::Reference const xStreamSI{xStream, uno::UNO_QUERY_THROW}; + if (!xStreamSI->supportsService("com.sun.star.packages.PackageStream")) + { + SAL_INFO("package", "entry STORED with data descriptor is folder: \"" << rEntry.sPath << "\""); + throw ZipIOException( + THROW_WHERE + "entry STORED with data descriptor is folder"); + } if (!xStream->getPropertyValue("WasEncrypted").get()) { SAL_INFO("package", "entry STORED with data descriptor but not encrypted: \"" << rEntry.sPath << "\"");