summaryrefslogtreecommitdiff
path: root/package/qa
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2024-07-05 13:57:16 +0200
committerMichael Stahl <michael.stahl@allotropia.de>2024-09-19 09:42:41 +0200
commitaeb92985f58629a112b4d1f4d105de8c372735b8 (patch)
treeca37f30a656d289bdbd5c7e40566c685b6aebd60 /package/qa
parentceff75b533654154ac077a7313ebebd53aedaa5e (diff)
package: add unit tests with invalid zip packages
Change-Id: I687028391833ea48884912b0e5f586b95eee3244 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170054 Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> Tested-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'package/qa')
-rw-r--r--package/qa/cppunit/data/casing.docxbin0 -> 6445 bytes
-rw-r--r--package/qa/cppunit/data/dd-deflated.docxbin0 -> 12576 bytes
-rw-r--r--package/qa/cppunit/data/dd-stored.docxbin0 -> 12574 bytes
-rw-r--r--package/qa/cppunit/data/dot-slash.docxbin0 -> 5608 bytes
-rw-r--r--package/qa/cppunit/data/duplicate-files.odtbin0 -> 10091 bytes
-rw-r--r--package/qa/cppunit/data/inner-gap.docxbin0 -> 12289 bytes
-rw-r--r--package/qa/cppunit/data/overlap.docxbin0 -> 12687 bytes
-rw-r--r--package/qa/cppunit/data/slash.odtbin0 -> 10093 bytes
-rw-r--r--package/qa/cppunit/data/two-zips.docxbin0 -> 9960 bytes
-rw-r--r--package/qa/cppunit/data/two-zips.odtbin0 -> 18144 bytes
-rw-r--r--package/qa/cppunit/data/unicode-path.docxbin0 -> 5720 bytes
-rw-r--r--package/qa/cppunit/data/unicode-path.odtbin0 -> 10207 bytes
-rw-r--r--package/qa/cppunit/data/zip64-eocd.docxbin0 -> 12251 bytes
-rw-r--r--package/qa/cppunit/test_zippackage.cxx390
14 files changed, 390 insertions, 0 deletions
diff --git a/package/qa/cppunit/data/casing.docx b/package/qa/cppunit/data/casing.docx
new file mode 100644
index 000000000000..d8d0dffc71a6
--- /dev/null
+++ b/package/qa/cppunit/data/casing.docx
Binary files differ
diff --git a/package/qa/cppunit/data/dd-deflated.docx b/package/qa/cppunit/data/dd-deflated.docx
new file mode 100644
index 000000000000..a4638147ce91
--- /dev/null
+++ b/package/qa/cppunit/data/dd-deflated.docx
Binary files differ
diff --git a/package/qa/cppunit/data/dd-stored.docx b/package/qa/cppunit/data/dd-stored.docx
new file mode 100644
index 000000000000..41c19338821d
--- /dev/null
+++ b/package/qa/cppunit/data/dd-stored.docx
Binary files differ
diff --git a/package/qa/cppunit/data/dot-slash.docx b/package/qa/cppunit/data/dot-slash.docx
new file mode 100644
index 000000000000..d50cabcbdee2
--- /dev/null
+++ b/package/qa/cppunit/data/dot-slash.docx
Binary files differ
diff --git a/package/qa/cppunit/data/duplicate-files.odt b/package/qa/cppunit/data/duplicate-files.odt
new file mode 100644
index 000000000000..cc24f7024ad1
--- /dev/null
+++ b/package/qa/cppunit/data/duplicate-files.odt
Binary files differ
diff --git a/package/qa/cppunit/data/inner-gap.docx b/package/qa/cppunit/data/inner-gap.docx
new file mode 100644
index 000000000000..d8e9a232465c
--- /dev/null
+++ b/package/qa/cppunit/data/inner-gap.docx
Binary files differ
diff --git a/package/qa/cppunit/data/overlap.docx b/package/qa/cppunit/data/overlap.docx
new file mode 100644
index 000000000000..2d5d115ed800
--- /dev/null
+++ b/package/qa/cppunit/data/overlap.docx
Binary files differ
diff --git a/package/qa/cppunit/data/slash.odt b/package/qa/cppunit/data/slash.odt
new file mode 100644
index 000000000000..22c6443499af
--- /dev/null
+++ b/package/qa/cppunit/data/slash.odt
Binary files differ
diff --git a/package/qa/cppunit/data/two-zips.docx b/package/qa/cppunit/data/two-zips.docx
new file mode 100644
index 000000000000..720189b20ed9
--- /dev/null
+++ b/package/qa/cppunit/data/two-zips.docx
Binary files differ
diff --git a/package/qa/cppunit/data/two-zips.odt b/package/qa/cppunit/data/two-zips.odt
new file mode 100644
index 000000000000..36d90cb9d4d9
--- /dev/null
+++ b/package/qa/cppunit/data/two-zips.odt
Binary files differ
diff --git a/package/qa/cppunit/data/unicode-path.docx b/package/qa/cppunit/data/unicode-path.docx
new file mode 100644
index 000000000000..1855aa1e7408
--- /dev/null
+++ b/package/qa/cppunit/data/unicode-path.docx
Binary files differ
diff --git a/package/qa/cppunit/data/unicode-path.odt b/package/qa/cppunit/data/unicode-path.odt
new file mode 100644
index 000000000000..9edaaeb68809
--- /dev/null
+++ b/package/qa/cppunit/data/unicode-path.odt
Binary files differ
diff --git a/package/qa/cppunit/data/zip64-eocd.docx b/package/qa/cppunit/data/zip64-eocd.docx
new file mode 100644
index 000000000000..1a4dbd0d16b1
--- /dev/null
+++ b/package/qa/cppunit/data/zip64-eocd.docx
Binary files differ
diff --git a/package/qa/cppunit/test_zippackage.cxx b/package/qa/cppunit/test_zippackage.cxx
new file mode 100644
index 000000000000..624457ab7bcf
--- /dev/null
+++ b/package/qa/cppunit/test_zippackage.cxx
@@ -0,0 +1,390 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <unotest/bootstrapfixturebase.hxx>
+
+#include <com/sun/star/beans/NamedValue.hpp>
+#include <com/sun/star/embed/StorageFormats.hpp>
+#include <com/sun/star/packages/zip/ZipIOException.hpp>
+
+using namespace ::com::sun::star;
+
+class ZipPackageTest : public test::BootstrapFixtureBase
+{
+};
+
+auto const ZipPackage(u"com.sun.star.packages.comp.ZipPackage"_ustr);
+
+CPPUNIT_TEST_FIXTURE(ZipPackageTest, testDuplicate)
+{
+ auto const url(m_directories.getURLFromSrc(u"/package/qa/cppunit/data/duplicate-files.odt"));
+ uno::Sequence<uno::Any> const args{
+ uno::Any(url),
+ uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
+ };
+
+ CPPUNIT_ASSERT_THROW(m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ ZipPackage, args, m_xContext),
+ css::packages::zip::ZipIOException);
+
+ try
+ {
+ uno::Sequence<uno::Any> 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_FIXTURE(ZipPackageTest, testUnicodeODT)
+{
+ auto const url(m_directories.getURLFromSrc(u"/package/qa/cppunit/data/unicode-path.odt"));
+ uno::Sequence<uno::Any> const args{
+ uno::Any(url),
+ uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
+ };
+
+ // don't load corrupted zip file
+ CPPUNIT_ASSERT_THROW(m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ ZipPackage, args, m_xContext),
+ css::packages::zip::ZipIOException);
+
+ try
+ {
+ uno::Sequence<uno::Any> 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_FIXTURE(ZipPackageTest, testUnicodeDOCX)
+{
+ auto const url(m_directories.getURLFromSrc(u"/package/qa/cppunit/data/unicode-path.docx"));
+ uno::Sequence<uno::Any> const args{
+ uno::Any(url),
+ uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
+ };
+
+ // don't load corrupted zip file
+ CPPUNIT_ASSERT_THROW(m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ ZipPackage, args, m_xContext),
+ css::packages::zip::ZipIOException);
+
+ try
+ {
+ uno::Sequence<uno::Any> 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_FIXTURE(ZipPackageTest, testAbsolutePathODT)
+{
+ auto const url(m_directories.getURLFromSrc(u"/package/qa/cppunit/data/slash.odt"));
+ uno::Sequence<uno::Any> const args{
+ uno::Any(url),
+ uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
+ };
+
+ // don't load corrupted zip file
+ CPPUNIT_ASSERT_THROW(m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ ZipPackage, args, m_xContext),
+ css::packages::zip::ZipIOException);
+
+ try
+ {
+ uno::Sequence<uno::Any> 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_FIXTURE(ZipPackageTest, testDotPathDOCX)
+{
+ auto const url(m_directories.getURLFromSrc(u"/package/qa/cppunit/data/dot-slash.docx"));
+ uno::Sequence<uno::Any> const args{
+ uno::Any(url),
+ uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
+ };
+
+ // don't load corrupted zip file
+ CPPUNIT_ASSERT_THROW(m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ ZipPackage, args, m_xContext),
+ css::packages::zip::ZipIOException);
+
+ try
+ {
+ uno::Sequence<uno::Any> 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_FIXTURE(ZipPackageTest, testConcatODT)
+{
+ auto const url(m_directories.getURLFromSrc(u"/package/qa/cppunit/data/two-zips.odt"));
+ uno::Sequence<uno::Any> const args{
+ uno::Any(url),
+ uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
+ };
+
+ // don't load corrupted zip file
+ CPPUNIT_ASSERT_THROW(m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ ZipPackage, args, m_xContext),
+ css::packages::zip::ZipIOException);
+
+ try
+ {
+ uno::Sequence<uno::Any> 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_FIXTURE(ZipPackageTest, testConcatDOCX)
+{
+ auto const url(m_directories.getURLFromSrc(u"/package/qa/cppunit/data/two-zips.docx"));
+ uno::Sequence<uno::Any> const args{
+ uno::Any(url),
+ uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
+ };
+
+ // don't load corrupted zip file
+ CPPUNIT_ASSERT_THROW(m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ ZipPackage, args, m_xContext),
+ css::packages::zip::ZipIOException);
+
+ try
+ {
+ uno::Sequence<uno::Any> 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_FIXTURE(ZipPackageTest, testCaseInsensitiveDOCX)
+{
+ auto const url(m_directories.getURLFromSrc(u"/package/qa/cppunit/data/casing.docx"));
+ uno::Sequence<uno::Any> const args{
+ uno::Any(url),
+ uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::OFOPXML)))
+ };
+
+ // don't load corrupted zip file
+ CPPUNIT_ASSERT_THROW(m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ ZipPackage, args, m_xContext),
+ css::packages::zip::ZipIOException);
+
+ try
+ {
+ uno::Sequence<uno::Any> 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_FIXTURE(ZipPackageTest, testOverlapDOCX)
+{
+ auto const url(m_directories.getURLFromSrc(u"/package/qa/cppunit/data/overlap.docx"));
+ uno::Sequence<uno::Any> const args{
+ uno::Any(url),
+ uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
+ };
+
+ // don't load corrupted zip file
+ CPPUNIT_ASSERT_THROW(m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ ZipPackage, args, m_xContext),
+ css::packages::zip::ZipIOException);
+
+ try
+ {
+ uno::Sequence<uno::Any> 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_FIXTURE(ZipPackageTest, testInnerGapDOCX)
+{
+ auto const url(m_directories.getURLFromSrc(u"/package/qa/cppunit/data/inner-gap.docx"));
+ uno::Sequence<uno::Any> const args{
+ uno::Any(url),
+ uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
+ };
+
+ // don't load corrupted zip file
+ CPPUNIT_ASSERT_THROW(m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ ZipPackage, args, m_xContext),
+ css::packages::zip::ZipIOException);
+
+ try
+ {
+ uno::Sequence<uno::Any> 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_FIXTURE(ZipPackageTest, testDataDescriptorDeflatedDOCX)
+{
+ auto const url(m_directories.getURLFromSrc(u"/package/qa/cppunit/data/dd-deflated.docx"));
+ uno::Sequence<uno::Any> const args{
+ uno::Any(url),
+ uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
+ };
+
+ // don't load corrupted zip file
+ CPPUNIT_ASSERT_THROW(m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ ZipPackage, args, m_xContext),
+ css::packages::zip::ZipIOException);
+
+ try
+ {
+ uno::Sequence<uno::Any> 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_FIXTURE(ZipPackageTest, testDataDescriptorStoredDOCX)
+{
+ auto const url(m_directories.getURLFromSrc(u"/package/qa/cppunit/data/dd-stored.docx"));
+ uno::Sequence<uno::Any> const args{
+ uno::Any(url),
+ uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::OFOPXML)))
+ };
+
+ // don't load corrupted zip file
+ CPPUNIT_ASSERT_THROW(m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ ZipPackage, args, m_xContext),
+ css::packages::zip::ZipIOException);
+
+ try
+ {
+ uno::Sequence<uno::Any> const args2{
+ uno::Any(url), uno::Any(beans::NamedValue(u"RepairPackage"_ustr, uno::Any(true))),
+ uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::OFOPXML)))
+ };
+ 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_FIXTURE(ZipPackageTest, testZip64End)
+{
+ auto const url(m_directories.getURLFromSrc(u"/package/qa/cppunit/data/zip64-eocd.docx"));
+ uno::Sequence<uno::Any> const args{
+ uno::Any(url),
+ uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::ZIP)))
+ };
+
+ // don't load corrupted zip file
+ CPPUNIT_ASSERT_THROW(m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ ZipPackage, args, m_xContext),
+ css::packages::zip::ZipIOException);
+
+ try
+ {
+ uno::Sequence<uno::Any> 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();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */