From 3efad499bf4f7623610a54f9f14622de4954352f Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Mon, 14 Oct 2024 12:04:05 +0200 Subject: [PATCH] tdf#163364 package: ask to recover for this invalid ODF package Bugdoc has a data descriptor on a folder entry, which is very odd and entirely pointless. Which is also the first entry, so it's an invalid ODF package anyway. ZipPackageFolder throws UnknownPropertyException for "WasEncrypted", which results in General I/O error, but we want to ask the user if the file should be opened in recovery mode. (regression from commit 32cad89592ec04ab552399095c91dd76afb3002c) Change-Id: Iafe610d507cf92d2fd2e9c3040592c3e638a30dd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174889 Tested-by: Jenkins Reviewed-by: Michael Stahl --- package/qa/cppunit/data/tdf163364.ods | Bin 0 -> 2572 bytes package/qa/cppunit/test_zippackage.cxx | 28 +++++++++++++++++++++++ package/source/zippackage/ZipPackage.cxx | 8 +++++++ 3 files changed, 36 insertions(+) create mode 100644 package/qa/cppunit/data/tdf163364.ods diff --git a/package/qa/cppunit/data/tdf163364.ods b/package/qa/cppunit/data/tdf163364.ods new file mode 100644 index 0000000000000000000000000000000000000000..a772aebdbc7ee2b7e4ce882b4bccada2ab9f52a4 GIT binary patch literal 2572 zcmZ{m2{hDi7stmo44RQ8N%o~EON8v}U>eJiNcI@XGLxn7w{L^gpHSA3waEInizpdM zWSwj=qy>|=7?Lpa&ggw>>b&p$oqO)@oZs_(exGxnd!Bm{a3*G602=@RxNZcqr-q*f zqQ03!ZS>_}7RCw)I4f<H~2xOjjid|@9&|tl7i+vUB&N;}! zz8(KKnlUMp?$O>+2t#XeyaZlcR1Du5a?zN&;>M)g3RCqR5OJ@9_=|5I7Ow%41 zw!W3Ej*IaqyfMYlaYXECYrsobwP+TwF_*Y;o~@S?HzX%y6Yxq9A=q8q2$~O%ZU$#9 z%YVjjO;>Hd;n*I=N3gg)Muqkdb6^9%c>W`y;MI;~npF)kX^UGA9=0Km&*000Ly zXYOcJ5E8YYsrMJHELTi9#(HW*um2U? z5apH;vD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=Ax){jDFi&Z|;Qe zFwt5OJ9?y`N17f{76yWgze@PvC#j;F#Rpk(%@HUYEAMj> z#~npTzdhGYJVKE|i)=lQWTipUqaff6jKWO+e>kC%?i)p)7JkkgzhwV=IH4_Opn7wR z8oi8uRQYoY`Vyq|YMTAn!iO5@I`^MK`qKFC{PaUu1N>F5f2!zDidHr>`=PRA{k@3( jRMMx9c9Jyvq5Miy{ybL%oQ3*-002mR9H 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 << "\"");