sdext/source/pdfimport/filterdet.cxx | 48 +++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 13 deletions(-)
New commits: commit f3fd83098f3020c9f69032911754a5c1d2fc4fd5 Author: Dr. David Alan Gilbert <d...@treblig.org> AuthorDate: Thu Apr 10 23:57:29 2025 +0100 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Tue Apr 22 04:37:35 2025 +0200 tdf#55425,tdf#66580: sdext,pdfimport: Always stash password Always stash the password in the detect phase, even if it's not a hybrid. This lets the plain PDF import use that password. Change-Id: Iebcd85428ebf81ea483543892687cf2ed56473ec Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183992 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 82474602a992..56d143d3a5a2 100644 --- a/sdext/source/pdfimport/filterdet.cxx +++ b/sdext/source/pdfimport/filterdet.cxx @@ -496,6 +496,19 @@ OUString SAL_CALL PDFDetector::detect( uno::Sequence< beans::PropertyValue >& rF aOutFilterName = "calc_pdf_addstream_import"; } + // Stash the password so that the importer can use it, even if we came to the + // conclusion that it's not a hybrid, the PDF import side can use it. + if (!aPassword.isEmpty()) + { + if (nPasswordPos == -1) + { + nPasswordPos = nAttribs; + rFilterData.realloc(++nAttribs); + rFilterData.getArray()[nPasswordPos].Name = "Password"; + } + rFilterData.getArray()[nPasswordPos].Value <<= aPassword; + } + if (!aOutFilterName.isEmpty()) { if( nFilterNamePos == -1 ) @@ -515,17 +528,6 @@ OUString SAL_CALL PDFDetector::detect( uno::Sequence< beans::PropertyValue >& rF pFilterData[nAttribs-1].Name = "EmbeddedSubstream"; pFilterData[nAttribs-1].Value <<= xEmbedStream; } - if (!aPassword.isEmpty()) - { - if (nPasswordPos == -1) - { - nPasswordPos = nAttribs; - rFilterData.realloc(++nAttribs); - pFilterData = rFilterData.getArray(); - pFilterData[nPasswordPos].Name = "Password"; - } - pFilterData[nPasswordPos].Value <<= aPassword; - } } else { commit 0d4d2563091eccb125a3d0f11b2df858d059d6a7 Author: Dr. David Alan Gilbert <d...@treblig.org> AuthorDate: Thu Apr 10 01:15:17 2025 +0100 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Tue Apr 22 04:37:20 2025 +0200 tdf#55425, tdf#66580: sdext,pdfimport: Extract the embedded file At this point we're pretty sure the embedded file is a hybrid. Extract it. Change-Id: Id1aa42136692a1500a08455c6e7af5af3576b431 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183952 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 96fbfa5cc79b..82474602a992 100644 --- a/sdext/source/pdfimport/filterdet.cxx +++ b/sdext/source/pdfimport/filterdet.cxx @@ -302,9 +302,9 @@ constexpr FilenameMime aFilenameMimeMap[] = { // be exactly one embedded file. // This uses PDFium to do the legwork. uno::Reference<io::XStream> getEmbeddedFile(const OUString& rInPDFFileURL, - OUString& /*rOutMimetype*/, + OUString& rOutMimetype, OUString& /*io_rPwd*/, - const uno::Reference<uno::XComponentContext>& /*xContext*/, + const uno::Reference<uno::XComponentContext>& xContext, const uno::Sequence<beans::PropertyValue>& /*rFilterData*/, bool /*bMayUseUI*/) { @@ -386,6 +386,26 @@ uno::Reference<io::XStream> getEmbeddedFile(const OUString& rInPDFFileURL, } SAL_INFO("sdext.pdfimport", "getEmbeddedFile pdfium open"); + std::vector<sal_uInt8> aExtractedFileBuf; + if (!pAttachment->getFile(aExtractedFileBuf)) + { + break; + } + SAL_INFO("sdext.pdfimport", "getEmbeddedFile file buffer length: " << aExtractedFileBuf.size()); + // Based on FileEmitContext above, we want to stash the data in a TempFile + // but need an XStream + uno::Reference<io::XStream> xContextStream; + uno::Reference<io::XSeekable> xSeek; + xContextStream.set(io::TempFile::create(xContext), uno::UNO_QUERY_THROW); + auto xOut = xContextStream->getOutputStream(); + xSeek.set(xOut, uno::UNO_QUERY_THROW); + // writeBytes wants a Uno::Sequence rather than the std::vector above, convert again + uno::Sequence<sal_Int8> aExtractedFileSeq(reinterpret_cast<sal_Int8 *>(aExtractedFileBuf.data()), aExtractedFileBuf.size()); + xOut->writeBytes(aExtractedFileSeq); + + xEmbed = xContextStream; + rOutMimetype = aMimetype; + SAL_INFO("sdext.pdfimport", "getEmbeddedFile returning stream"); } while(false); osl_unmapMappedFile(fileHandle, pMemRawPdf, nFileSize);