vcl/qa/cppunit/filter/ipdf/data/dict-array-dict.pdf | 55 ++++++++++++++++++++ vcl/qa/cppunit/filter/ipdf/ipdf.cxx | 21 +++++++ vcl/source/filter/ipdf/pdfdocument.cxx | 13 ++++ 3 files changed, 87 insertions(+), 2 deletions(-)
New commits: commit 056c1284d6a68525002c54bef10834cc135385db Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Fri Oct 16 18:15:21 2020 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Fri Oct 16 20:57:34 2020 +0200 vcl pdf tokenizer: fix handling of dict -> array -> dict tokens Needed to be able to parse the /Reference key of signatures. Change-Id: I6b81089a3f58a2de461ad92ca5a891c284f8686a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104443 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/vcl/qa/cppunit/filter/ipdf/data/dict-array-dict.pdf b/vcl/qa/cppunit/filter/ipdf/data/dict-array-dict.pdf new file mode 100644 index 000000000000..73de3117b9a6 --- /dev/null +++ b/vcl/qa/cppunit/filter/ipdf/data/dict-array-dict.pdf @@ -0,0 +1,55 @@ +%PDF-1.7 +%��� +1 0 obj << + /Type /Catalog + /Pages 2 0 R +>> +endobj +2 0 obj << + /Type /Pages + /MediaBox [0 0 200 300] + /Count 1 + /Kids [3 0 R] +>> +endobj +3 0 obj << + /Type /Page + /Parent 2 0 R + /Contents 4 0 R + /Key[<</InnerKey 42>>] +>> +endobj +4 0 obj << + /Length 188 +>> +stream +q +0 0 0 rg +0 290 10 10 re B* +10 150 50 30 re B* +0 0 1 rg +190 290 10 10 re B* +70 232 50 30 re B* +0 1 0 rg +190 0 10 10 re B* +130 150 50 30 re B* +1 0 0 rg +0 0 10 10 re B* +70 67 50 30 re B* +Q +endstream +endobj +xref +0 5 +0000000000 65535 f +0000000015 00000 n +0000000068 00000 n +0000000157 00000 n +0000000251 00000 n +trailer << + /Root 1 0 R + /Size 5 +>> +startxref +491 +%%EOF diff --git a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx index 96fd331ceb76..683a87f33995 100644 --- a/vcl/qa/cppunit/filter/ipdf/ipdf.cxx +++ b/vcl/qa/cppunit/filter/ipdf/ipdf.cxx @@ -26,6 +26,7 @@ #include <svx/signaturelinehelper.hxx> #include <sfx2/objsh.hxx> #include <vcl/filter/PDFiumLibrary.hxx> +#include <vcl/filter/pdfdocument.hxx> using namespace ::com::sun::star; @@ -140,6 +141,26 @@ CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, testPDFAddVisibleSignatureLastPage) CPPUNIT_ASSERT_EQUAL(4, pAnnot->getObjectCount()); } +CPPUNIT_TEST_FIXTURE(VclFilterIpdfTest, testDictArrayDict) +{ + // Load a file that has markup like this: + // 3 0 obj << + // /Key[<</InnerKey 42>>] + // >> + OUString aSourceURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "dict-array-dict.pdf"; + SvFileStream aFile(aSourceURL, StreamMode::READ); + vcl::filter::PDFDocument aDocument; + CPPUNIT_ASSERT(aDocument.Read(aFile)); + std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages(); + CPPUNIT_ASSERT(!aPages.empty()); + vcl::filter::PDFObjectElement* pPage = aPages[0]; + auto pKey = dynamic_cast<vcl::filter::PDFArrayElement*>(pPage->Lookup("Key")); + + // Without the accompanying fix in place, this test would have failed, because the value of Key + // was a dictionary element, not an array element. + CPPUNIT_ASSERT(pKey); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/filter/ipdf/pdfdocument.cxx b/vcl/source/filter/ipdf/pdfdocument.cxx index ec763d54a2a1..2b6c9d49de34 100644 --- a/vcl/source/filter/ipdf/pdfdocument.cxx +++ b/vcl/source/filter/ipdf/pdfdocument.cxx @@ -2406,8 +2406,17 @@ size_t PDFDictionaryElement::Parse(const std::vector<std::unique_ptr<PDFElement> if (nexti >= i) // ensure we go forwards and not endlessly loop { i = nexti; - rDictionary[aName] = pDictionary; - aName.clear(); + if (pArray) + { + // Dictionary value inside an array. + pArray->PushBack(pDictionary); + } + else + { + // Dictionary toplevel value. + rDictionary[aName] = pDictionary; + aName.clear(); + } } } }
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits