sdext/source/pdfimport/filterdet.cxx |   32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

New commits:
commit b7a8ce65b47bd85e31ae3ff8e81f23f79380de87
Author:     Dr. David Alan Gilbert <d...@treblig.org>
AuthorDate: Thu Apr 10 01:11:57 2025 +0100
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Tue Apr 22 04:37:04 2025 +0200

    tdf#55425, tdf#66580: sdext,pdfimport: Filename/MIME lookup
    
    Look up the filename of the embedded file and find the MIME type we
    associate with it.  If the name doesn't match, then it's not a LO
    hybrid file.
    When PDFium can read the MIME type, we'll be able to check
    this MIME type against what is in the PDF.
    
    Change-Id: Iebccf67c1d86e7c6c16c2c1c9ed8d1c08df758fb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183951
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/sdext/source/pdfimport/filterdet.cxx 
b/sdext/source/pdfimport/filterdet.cxx
index b817b15d523b..96fbfa5cc79b 100644
--- a/sdext/source/pdfimport/filterdet.cxx
+++ b/sdext/source/pdfimport/filterdet.cxx
@@ -283,6 +283,18 @@ bool copyToTemp(uno::Reference<io::XInputStream> const& 
xInput, oslFileHandle& r
     return false;
 }
 
+struct FilenameMime {
+    OUString aFilename;
+    OUString aMimetype;
+};
+
+constexpr FilenameMime aFilenameMimeMap[] = {
+    { u"Original.odt"_ustr, u"application/vnd.oasis.opendocument.text"_ustr },
+    { u"Original.odp"_ustr, 
u"application/vnd.oasis.opendocument.presentation"_ustr },
+    { u"Original.ods"_ustr, 
u"application/vnd.oasis.opendocument.spreadsheet"_ustr },
+    { u"Original.odg"_ustr, 
u"application/vnd.oasis.opendocument.graphics"_ustr },
+};
+
 } // end anonymous namespace
 
 // Check for a hybrid that is stored using the newer method, the standard PDF 
embedded file
@@ -354,6 +366,26 @@ uno::Reference<io::XStream> getEmbeddedFile(const 
OUString& rInPDFFileURL,
             // see https://issues.chromium.org/issues/408241034
             // When it does we can check the filename matches the expected 
mimetype
             SAL_INFO("sdext.pdfimport", "getEmbeddedFile attachment name: " << 
aName);
+
+            // Find the mimetype for the filename
+            OUString aMimetype;
+
+            for (auto& rFM : aFilenameMimeMap)
+            {
+                if (rFM.aFilename == aName)
+                {
+                    aMimetype = rFM.aMimetype;
+                    break;
+                }
+            }
+            SAL_INFO("sdext.pdfimport", "getEmbeddedFile mimetype: " << 
aMimetype);
+            // If we don't match, then this is a non-hybrid file with a normal 
attachment
+            if (aMimetype.isEmpty())
+            {
+                break;
+            }
+
+            SAL_INFO("sdext.pdfimport", "getEmbeddedFile pdfium open");
         } while(false);
 
         osl_unmapMappedFile(fileHandle, pMemRawPdf, nFileSize);

Reply via email to