sdext/qa/unit/data/tdf55425_crypt-pdf20-passa.pdf |binary sdext/qa/unit/pdfimport.cxx | 17 +++++ sdext/source/pdfimport/README.md | 71 ++++++++++++++++++++++ 3 files changed, 88 insertions(+)
New commits: commit 1622d672b8cc721d5f9917931f6d8d999f218f7a Author: Dr. David Alan Gilbert <d...@treblig.org> AuthorDate: Sun Feb 16 15:47:10 2025 +0000 Commit: David Gilbert <d...@treblig.org> CommitDate: Tue Mar 4 00:58:31 2025 +0100 tdf#55425:sdext,pdfimport: Document the new protocol Document the new protocol between the two processes. Change-Id: I3873e78a1832d9125d80c5a3238efc20d45918f9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181751 Reviewed-by: David Gilbert <freedesk...@treblig.org> Tested-by: Jenkins diff --git a/sdext/source/pdfimport/README.md b/sdext/source/pdfimport/README.md index 83850833f54c..7afdcc5ced1e 100644 --- a/sdext/source/pdfimport/README.md +++ b/sdext/source/pdfimport/README.md @@ -87,6 +87,77 @@ wrapper layer. The tree is then 'visited' by optimisation layers and then by backend specific XML generators (e.g. for Draw and Writer) that then generate an XML stream to be parsed by the core of LibreOffice. +## The wrapper protocol + +The LibreOffice wrapper talks to the GPL wrapper code over a pipe +using a simple line based protocol before the main decoding is done. + +The commands are: + +- *Pmypassword* - set the password to be used for future opening of the PDF, +it can be empty. + +- *O* - Open the PDF document using the password. This returns a response +line which is either **#OPEN** when it worked or **#ERROR**. The **#ERROR** +includes information on the failure shown below. + +- *G* - Go - ie render the document using the previously provided document. +No more commands are accepted after this point, the structure is dumped +to stdout, and the binary data blobs go to stderr. + +- *E* - Exit without doing anything more with the file. Used when you give +up on password attempts. + +Some example runs might be: + +- A normal unencrypted document: + +``` + P + O + #OPEN + G +``` + +- An encrypted document: + +``` + P + O + #ERROR:2:ENCRYPTED + Psecret + O + #OPEN + G +``` + +- An encrypted document that we give up on: + +``` + P + O + #ERROR:2:ENCRYPTED + E +``` + +- A document with some other error: + +``` + P + O + #ERROR:1: + E +``` + +Note we don't rely on the error number in the code. + +## Hybrid documents + +PDF can contain other files, one use of which is to store the original document +file that was used to generate the PDF. + +TBD: Once I figure out how it works. + ## Bug handling - Please tag bugs with *filter:pdf* in component *filters and storage*. commit 4aba4d73969dccc983dee52581faecef78ddea2b Author: Dr. David Alan Gilbert <d...@treblig.org> AuthorDate: Sun Feb 16 14:59:24 2025 +0000 Commit: David Gilbert <d...@treblig.org> CommitDate: Tue Mar 4 00:58:20 2025 +0100 tdf#55425:sdext,pdfimport: Add a test Add a test for opening a PDF2.0 encrypted file. It was generated by exporting it from LO with the type set as PDF2.0 and specifying a password. Change-Id: I0c23768de6c8a931acfe8b89ca550b406ec8aeb4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181750 Reviewed-by: David Gilbert <freedesk...@treblig.org> Tested-by: Jenkins diff --git a/sdext/qa/unit/data/tdf55425_crypt-pdf20-passa.pdf b/sdext/qa/unit/data/tdf55425_crypt-pdf20-passa.pdf new file mode 100644 index 000000000000..d232ed9acf0a Binary files /dev/null and b/sdext/qa/unit/data/tdf55425_crypt-pdf20-passa.pdf differ diff --git a/sdext/qa/unit/pdfimport.cxx b/sdext/qa/unit/pdfimport.cxx index b029014d96d8..68a9b7580b26 100644 --- a/sdext/qa/unit/pdfimport.cxx +++ b/sdext/qa/unit/pdfimport.cxx @@ -483,6 +483,22 @@ namespace #endif } + void testTdf55425_decrypt() + { +#if HAVE_FEATURE_POPPLER + // This tries to load an encrypted file + // It was created with LO set to PDF2.0 and with a password set + auto pSink = std::make_shared<TestSink>(); + CPPUNIT_ASSERT( + pdfi::xpdf_ImportFromFile( + m_directories.getURLFromSrc(u"/sdext/qa/unit/data/tdf55425_crypt-pdf20-passa.pdf"), + pSink, + uno::Reference< task::XInteractionHandler >(), + u"a"_ustr, // Critically secure test password + getComponentContext(), u""_ustr)); +#endif + } + void testOdfDrawExport() { #if HAVE_FEATURE_POPPLER @@ -901,6 +917,7 @@ namespace CPPUNIT_TEST(testTdf78427_FontWeight_MyraidProSemibold); CPPUNIT_TEST(testTdf143959_nameFromFontFile); CPPUNIT_TEST(testTdf104597_textrun); + CPPUNIT_TEST(testTdf55425_decrypt); CPPUNIT_TEST(testSpaces); CPPUNIT_TEST_SUITE_END(); };