package/qa/cppunit/data/tdf163341.ods |binary package/qa/cppunit/test_zippackage.cxx | 13 +++++++++++++ package/source/zipapi/ZipFile.cxx | 10 +++++----- 3 files changed, 18 insertions(+), 5 deletions(-)
New commits: commit 279f42fa8b19d4fe81c3bba4c7af21aa8ab135b9 Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Mon Oct 14 13:52:12 2024 +0200 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Mon Oct 14 15:56:42 2024 +0200 tdf#163341 package: fix reading Zip64 produced by stream-write-ods 1. Accept 0xFFFF as nEndDisk/nEndDirDisk - the Zip APPNOTE says that values that don't fit into 16 bits SHOULD be 0xFFFF but it doesn't prohibit values that do fit (like, uhm, 0) to be written as 0xFFFF (regression from commit ca21cc985d57fffe7c834159b17c095206304994) 2. Fix misuse of o3tl::make_unsigned - it requires non-negative value, just do signed compare instead 3. Fix bad conversion from pointer to optional in ZipFile::readExtraFields() which effectively prevented the offset from being read (regression from commit efae4fc42d5fe3c0a69757226f38efc10d101194) Change-Id: Ib5e7776a30834e507b297fb28266b5489d1ab68d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174898 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/package/qa/cppunit/data/tdf163341.ods b/package/qa/cppunit/data/tdf163341.ods new file mode 100644 index 000000000000..5971e0123883 Binary files /dev/null and b/package/qa/cppunit/data/tdf163341.ods differ diff --git a/package/qa/cppunit/test_zippackage.cxx b/package/qa/cppunit/test_zippackage.cxx index 892f2979cd61..e8f3f910bb5a 100644 --- a/package/qa/cppunit/test_zippackage.cxx +++ b/package/qa/cppunit/test_zippackage.cxx @@ -412,6 +412,19 @@ CPPUNIT_TEST_FIXTURE(ZipPackageTest, testTdf163364) } } +CPPUNIT_TEST_FIXTURE(ZipPackageTest, testTdf163341) +{ + auto const url(m_directories.getURLFromSrc(u"/package/qa/cppunit/data/tdf163341.ods")); + uno::Sequence<uno::Any> const args{ + uno::Any(url), + uno::Any(beans::NamedValue("StorageFormat", uno::Any(embed::StorageFormats::PACKAGE))) + }; + + // this Zip64 should load successfully + m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(ZipPackage, args, + m_xContext); +} + //CPPUNIT_TEST_SUITE_REGISTRATION(...); //CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx index 450a6795ce2d..39a9cc4fca50 100644 --- a/package/source/zipapi/ZipFile.cxx +++ b/package/source/zipapi/ZipFile.cxx @@ -1187,12 +1187,12 @@ std::tuple<sal_Int64, sal_Int64, sal_Int64> ZipFile::findCentralDirectory() aGrabber.seek(nEndPos + 4); sal_uInt16 const nEndDisk = aGrabber.ReadUInt16(); - if (nEndDisk != 0) + if (nEndDisk != 0 && nEndDisk != 0xFFFF) { // only single disk is supported! throw ZipException(u"invalid end (disk)"_ustr ); } sal_uInt16 const nEndDirDisk = aGrabber.ReadUInt16(); - if (nEndDirDisk != 0) + if (nEndDirDisk != 0 && nEndDisk != 0xFFFF) { throw ZipException(u"invalid end (directory disk)"_ustr ); } @@ -1275,12 +1275,12 @@ std::tuple<sal_Int64, sal_Int64, sal_Int64> ZipFile::findCentralDirectory() { throw ZipException(u"inconsistent Zip/Zip64 end (entries)"_ustr); } - if (o3tl::make_unsigned(nEndDirSize) != sal_uInt32(-1) + if (nEndDirSize != -1 && nEnd64DirSize != nEndDirSize) { throw ZipException(u"inconsistent Zip/Zip64 end (size)"_ustr); } - if (o3tl::make_unsigned(nEndDirOffset) != sal_uInt32(-1) + if (nEndDirOffset != -1 && nEnd64DirOffset != nEndDirOffset) { throw ZipException(u"inconsistent Zip/Zip64 end (offset)"_ustr); @@ -1554,7 +1554,7 @@ bool ZipFile::readExtraFields(MemoryByteGrabber& aMemGrabber, sal_Int16 nExtraLe { nCompressedSize = aMemGrabber.ReadUInt64(); nReadSize = 16; - if (dataSize >= 24 && roOffset) + if (dataSize >= 24) { roOffset.emplace(aMemGrabber.ReadUInt64()); nReadSize = 24;