From a30330702d4dcafab3f8b0deae2485997e28a01d Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Fri, 13 Dec 2024 23:26:43 +0900 Subject: pdf: Fix embedded files when the PDF is encrypted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we encrypt the PDF and want to attach the ODF document to the PDF, the PDF file would not have any attachments when opened. This is because the encryption for the attachments and embedded files was not done correctly. This patch fixes this issue. Change-Id: I5bd8175f6067b8b684defa3b60746176f4314c8c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178447 Reviewed-by: Miklos Vajna Tested-by: Jenkins CollaboraOffice Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178771 Tested-by: Tomaž Vajngerl Reviewed-by: Tomaž Vajngerl --- vcl/inc/pdf/COSWriter.hxx | 5 ++++ vcl/source/gdi/pdfwriter_impl.cxx | 52 +++++++++++++++++++-------------------- 2 files changed, 30 insertions(+), 27 deletions(-) (limited to 'vcl') diff --git a/vcl/inc/pdf/COSWriter.hxx b/vcl/inc/pdf/COSWriter.hxx index 2142de1f846e..d63a2198a2e7 100644 --- a/vcl/inc/pdf/COSWriter.hxx +++ b/vcl/inc/pdf/COSWriter.hxx @@ -72,6 +72,11 @@ public: OStringBuffer& getLine() { return mrBuffer; } void startDict() { mrBuffer.append("<<"); } + void startDictWithKey(std::string_view key) + { + mrBuffer.append(key); + mrBuffer.append("<<"); + } void endDict() { mrBuffer.append(">>\n"); } void startStream() { mrBuffer.append("stream\n"); } diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index faf795fa60c7..cee972efb2fe 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -5233,26 +5233,28 @@ bool PDFWriterImpl::emitEmbeddedFiles() aLine.append(" /Params "); appendObjectReference(nParamsObject, aLine); aLine.append(">>\nstream\n"); - checkAndEnableStreamEncryption(rEmbeddedFile.m_nObject); if (!writeBuffer(aLine)) return false; - disableStreamEncryption(); aLine.setLength(0); sal_Int64 nSize{}; if (!rEmbeddedFile.m_aDataContainer.isEmpty()) { nSize = rEmbeddedFile.m_aDataContainer.getSize(); + checkAndEnableStreamEncryption(rEmbeddedFile.m_nObject); if (!writeBufferBytes(rEmbeddedFile.m_aDataContainer.getData(), rEmbeddedFile.m_aDataContainer.getSize())) return false; + disableStreamEncryption(); } else if (rEmbeddedFile.m_pStream) { + checkAndEnableStreamEncryption(rEmbeddedFile.m_nObject); sal_uInt64 nBegin = getCurrentFilePosition(); css::uno::Reference xStream(new PDFStreamIf(this)); rEmbeddedFile.m_pStream->write(xStream); rEmbeddedFile.m_pStream.reset(); xStream.clear(); nSize = sal_Int64(getCurrentFilePosition() - nBegin); + disableStreamEncryption(); } aLine.append("\nendstream\nendobj\n\n"); if (!writeBuffer(aLine)) return false; @@ -5361,29 +5363,26 @@ bool PDFWriterImpl::emitCatalog() { if (!updateObject(rAttachedFile.mnObjectId)) return false; - aLine.setLength( 0 ); + aLine.setLength(0); - appendObjectID(rAttachedFile.mnObjectId, aLine); - aLine.append("< "); + aWriter.startObject(rAttachedFile.mnObjectId); + aWriter.startDict(); + aWriter.write("/Type", "/Filespec"); + aWriter.writeKeyAndUnicodeEncrypt("/F", rAttachedFile.maFilename, rAttachedFile.mnObjectId); if (PDFWriter::PDFVersion::PDF_1_7 <= m_aContext.Version) { - aLine.append("/UF<"); - COSWriter::appendUnicodeTextString(rAttachedFile.maFilename, aLine); - aLine.append("> "); + aWriter.writeKeyAndUnicodeEncrypt("/UF", rAttachedFile.maFilename, rAttachedFile.mnObjectId); } if (!rAttachedFile.maDescription.isEmpty()) { - aLine.append("/Desc <"); - COSWriter::appendUnicodeTextString(rAttachedFile.maDescription, aLine); - aLine.append("> "); + aWriter.writeKeyAndUnicodeEncrypt("/Desc", rAttachedFile.maDescription, rAttachedFile.mnObjectId); } - aLine.append("/EF <>"); - aLine.append(">>\nendobj\n\n"); + aLine.append("/EF"); + aWriter.startDict(); + aWriter.writeKeyAndReference("/F", rAttachedFile.mnEmbeddedFileObjectId); + aWriter.endDict(); + aWriter.endDict(); + aWriter.endObject(); if (!writeBuffer(aLine)) return false; } @@ -5408,18 +5407,17 @@ bool PDFWriterImpl::emitCatalog() if (!m_aDocumentAttachedFiles.empty()) { - aLine.append("/Names "); - aLine.append("<'); - aLine.append(' '); - appendObjectReference(rAttachedFile.mnObjectId, aLine); + aWriter.writeUnicodeEncrypt(rAttachedFile.maFilename, m_nCatalogObject); + aWriter.writeReference(rAttachedFile.mnObjectId); } - aLine.append("]>>>>"); - aLine.append("\n" ); + aLine.append("]"); + aWriter.endDict(); + aWriter.endDict(); } if( m_aContext.PageLayout != PDFWriter::DefaultLayout ) -- cgit tion value='distro/lhm/libreoffice-5-2+backports'>distro/lhm/libreoffice-5-2+backports LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Expand)Author
2024-12-07Windows 7-8.1 support was removed, prevent install on these old systemsMike Kaganski
2024-10-30Adapt to generation of .worker.js files gone from 3.1.68Stephan Bergmann
2024-10-10Emscripten: For executables, only build .js files, not .html filesStephan Bergmann
2024-09-12tdf#162921 on this error dialog there is 'Abort' button, not 'Cancel'Andras Timar
2024-08-28Emscripten: Support --disable-guiStephan Bergmann
2024-08-03.NET Bindings: Move built .NET libraries into instdirRMZeroFour
2024-07-26Fix --with-package-format=emscriptenStephan Bergmann
2024-07-26Add --with-package-format=emscriptenStephan Bergmann
2024-05-16MSI: Adds the missing ExtendedType column in the CustomAction tablekubak
2024-05-03makefile simplification: replace $(call gb_CustomTarget_get_workdir,foo)Christian Lohmaier
2024-04-26use strawberry perl for installation packaging in wsl-as-helper caseChristian Lohmaier
2024-04-24MSI: Fix use of undefined TextStylekubak
2024-01-02Hard-code --with-online-update-mar-channel=LOOnlineUpdaterStephan Bergmann
2023-12-12Split --with-update-config=... into many --with-online-update-mar-...=...Stephan Bergmann
2023-11-17Missing parenthesisStephan Bergmann
2023-11-16fix --enable-wix switch - that didn't do anythingChristian Lohmaier
2023-11-09replace license in package header to MPL-2.0 in case of MPL subsetAndras Timar
2023-11-08msi packaging job-limiter: use CXX_FOR_BUILDChristian Lohmaier
2023-11-05limit parallelism during msi packaging stage to avoid cscript failuresChristian Lohmaier
2023-11-02MSI: Fix Signature table's FileName column typeMike Kaganski
2023-05-23Add configure switch to enable building the installer with WiX.Jussi Pakkanen
2023-04-26Disable WiX-based MSI generation for the momentThorsten Behrens
2023-04-22Integrate msicreator into LO and generate installerRakielle
2023-01-27Remove support for AIXStephan Bergmann
2022-12-13bump minimum make version to 4.0 (for $(file …) function)Christian Lohmaier
2022-12-08Stick to three-letter build step prefixesStephan Bergmann