package/inc/ZipFile.hxx                  |    2 +-
 package/source/zipapi/ZipFile.cxx        |   11 +++++++++++
 package/source/zippackage/ZipPackage.cxx |   12 ++++++++++--
 3 files changed, 22 insertions(+), 3 deletions(-)

New commits:
commit 04a33cd368ab77c636160915e4ac4721b7e10c5e
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Mon Sep 16 20:31:06 2024 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Sep 17 18:50:36 2024 +0200

    tdf#162866 package: fix loading AutoCorrect file with case-insensitive
    
    ... duplicates; the directory names of AutoCorrect entries are
    user-editable, so this needs to be supported.
    
    AutoCorrect uses an ODF package because the ODF document loading code
    requires the ODF document to be in an ODF storage with a MediaType
    property.
    
    AutoCorrect writes an empty mimetype file, and if such is present in an
    .odt file that is being loaded, existing checks will detect it as
    corrupted, so we can use this to check that the file is an AutoCorrect
    file and turn off the case-insensitive check.
    
    (regression from commit 4833f131243bdb409ddfaff8b4db87d4ed2af98f)
    
    Change-Id: I43887f7dad0c8cbb465b4c0f1c38bcc3244a7675
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173477
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    Tested-by: Jenkins
    (cherry picked from commit 9012355a60bd88db582078e38123863a4959b72f)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173492
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/package/inc/ZipFile.hxx b/package/inc/ZipFile.hxx
index 06912c3ac977..0824be493c64 100644
--- a/package/inc/ZipFile.hxx
+++ b/package/inc/ZipFile.hxx
@@ -56,7 +56,7 @@ class ZipEnumeration;
 class ZipFile
 {
 public:
-    enum class Checks { Default, CheckInsensitive };
+    enum class Checks { Default, CheckInsensitive, TryCheckInsensitive };
 
 private:
     rtl::Reference<comphelper::RefCountedMutex> m_aMutexHolder;
diff --git a/package/source/zipapi/ZipFile.cxx 
b/package/source/zipapi/ZipFile.cxx
index 4d0582ae5607..e91b5c49d25c 100644
--- a/package/source/zipapi/ZipFile.cxx
+++ b/package/source/zipapi/ZipFile.cxx
@@ -1470,6 +1470,17 @@ sal_Int32 ZipFile::readCEN()
                 SAL_INFO("package", "Duplicate CEN entry: \"" << aEntry.sPath 
<< "\"");
                 throw ZipException(u"Duplicate CEN entry"_ustr);
             }
+            if (aEntries.empty() && m_Checks == Checks::TryCheckInsensitive)
+            {
+                if (aEntry.sPath == "mimetype" && aEntry.nSize == 0)
+                {   // tdf#162866 AutoCorrect uses ODF package, directories are
+                    m_Checks = Checks::Default; // user-defined => ignore!
+                }
+                else
+                {
+                    m_Checks = Checks::CheckInsensitive;
+                }
+            }
             // this is required for OOXML, but not for ODF
             auto const lowerPath(aEntry.sPath.toAsciiLowerCase());
             if (!m_EntriesInsensitive.insert(lowerPath).second && m_Checks == 
Checks::CheckInsensitive)
diff --git a/package/source/zippackage/ZipPackage.cxx 
b/package/source/zippackage/ZipPackage.cxx
index 1c799f084570..a509ab976603 100644
--- a/package/source/zippackage/ZipPackage.cxx
+++ b/package/source/zippackage/ZipPackage.cxx
@@ -898,7 +898,11 @@ void SAL_CALL ZipPackage::initialize( const uno::Sequence< 
Any >& aArguments )
     {
         m_pZipFile.emplace(m_aMutexHolder, m_xContentStream, m_xContext, true,
             m_bForceRecovery,
-            m_nFormat == embed::StorageFormats::ZIP ? ZipFile::Checks::Default 
: ZipFile::Checks::CheckInsensitive);
+            m_nFormat == embed::StorageFormats::ZIP
+                ? ZipFile::Checks::Default
+                : m_nFormat == embed::StorageFormats::OFOPXML
+                    ? ZipFile::Checks::CheckInsensitive
+                    : ZipFile::Checks::TryCheckInsensitive);
         getZipFileContents();
     }
     catch ( IOException & e )
@@ -1273,7 +1277,11 @@ void ZipPackage::ConnectTo( const uno::Reference< 
io::XInputStream >& xInStream
     else
         m_pZipFile.emplace(m_aMutexHolder, m_xContentStream, m_xContext, false,
             false,
-            m_nFormat == embed::StorageFormats::ZIP ? ZipFile::Checks::Default 
: ZipFile::Checks::CheckInsensitive);
+            m_nFormat == embed::StorageFormats::ZIP
+                ? ZipFile::Checks::Default
+                : m_nFormat == embed::StorageFormats::OFOPXML
+                    ? ZipFile::Checks::CheckInsensitive
+                    : ZipFile::Checks::TryCheckInsensitive);
 }
 
 uno::Reference< io::XInputStream > ZipPackage::writeTempFile()

Reply via email to