[Libreoffice-commits] core.git: include/vcl vcl/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Aug 1 15:10:55 UTC 2018


 include/vcl/filter/pdfdocument.hxx     |    4 ++++
 vcl/source/filter/ipdf/pdfdocument.cxx |   20 ++++++++++++++++----
 2 files changed, 20 insertions(+), 4 deletions(-)

New commits:
commit 20e8d12c309d33a4c2937fa5ae041ac05a167de1
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Wed Aug 1 12:04:30 2018 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Wed Aug 1 17:10:27 2018 +0200

    forcepoint#65 pdf page visiting revisits itself
    
    Change-Id: I6d9eb75f0850a94814fb4d69ea1442b826674496
    Reviewed-on: https://gerrit.libreoffice.org/58416
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/vcl/filter/pdfdocument.hxx b/include/vcl/filter/pdfdocument.hxx
index 60acfe68c984..b19bfca6b408 100644
--- a/include/vcl/filter/pdfdocument.hxx
+++ b/include/vcl/filter/pdfdocument.hxx
@@ -63,6 +63,7 @@ class VCL_DLLPUBLIC PDFObjectElement : public PDFElement
     PDFDocument& m_rDoc;
     double m_fObjectValue;
     double m_fGenerationValue;
+    bool m_bVisiting;
     std::map<OString, PDFElement*> m_aDictionary;
     /// If set, the object contains this number element (outside any dictionary/array).
     PDFNumberElement* m_pNumberElement;
@@ -122,6 +123,9 @@ public:
     SvMemoryStream* GetStreamBuffer() const;
     void SetStreamBuffer(std::unique_ptr<SvMemoryStream>& pStreamBuffer);
     PDFDocument& GetDocument();
+
+    /// Visits the page tree recursively, looking for page objects.
+    void visitPages(std::vector<PDFObjectElement*>& rRet);
 };
 
 /// Array object: a list.
diff --git a/vcl/source/filter/ipdf/pdfdocument.cxx b/vcl/source/filter/ipdf/pdfdocument.cxx
index 28c49e53101d..7d4efc9e0eb0 100644
--- a/vcl/source/filter/ipdf/pdfdocument.cxx
+++ b/vcl/source/filter/ipdf/pdfdocument.cxx
@@ -1815,15 +1815,17 @@ size_t PDFDocument::GetObjectOffset(size_t nIndex) const
 const std::vector<std::unique_ptr<PDFElement>>& PDFDocument::GetElements() { return m_aElements; }
 
 /// Visits the page tree recursively, looking for page objects.
-static void visitPages(PDFObjectElement* pPages, std::vector<PDFObjectElement*>& rRet)
+void PDFObjectElement::visitPages(std::vector<PDFObjectElement*>& rRet)
 {
-    auto pKids = dynamic_cast<PDFArrayElement*>(pPages->Lookup("Kids"));
+    auto pKids = dynamic_cast<PDFArrayElement*>(Lookup("Kids"));
     if (!pKids)
     {
         SAL_WARN("vcl.filter", "visitPages: pages has no kids");
         return;
     }
 
+    m_bVisiting = true;
+
     for (const auto& pKid : pKids->GetElements())
     {
         auto pReference = dynamic_cast<PDFReferenceElement*>(pKid);
@@ -1834,14 +1836,23 @@ static void visitPages(PDFObjectElement* pPages, std::vector<PDFObjectElement*>&
         if (!pKidObject)
             continue;
 
+        // detect if visiting reenters itself
+        if (pKidObject->m_bVisiting)
+        {
+            SAL_WARN("vcl.filter", "visitPages: loop in hierarchy");
+            continue;
+        }
+
         auto pName = dynamic_cast<PDFNameElement*>(pKidObject->Lookup("Type"));
         if (pName && pName->GetValue() == "Pages")
             // Pages inside pages: recurse.
-            visitPages(pKidObject, rRet);
+            pKidObject->visitPages(rRet);
         else
             // Found an actual page.
             rRet.push_back(pKidObject);
     }
+
+    m_bVisiting = false;
 }
 
 std::vector<PDFObjectElement*> PDFDocument::GetPages()
@@ -1886,7 +1897,7 @@ std::vector<PDFObjectElement*> PDFDocument::GetPages()
         return aRet;
     }
 
-    visitPages(pPages, aRet);
+    pPages->visitPages(aRet);
 
     return aRet;
 }
@@ -2122,6 +2133,7 @@ PDFObjectElement::PDFObjectElement(PDFDocument& rDoc, double fObjectValue, doubl
     : m_rDoc(rDoc)
     , m_fObjectValue(fObjectValue)
     , m_fGenerationValue(fGenerationValue)
+    , m_bVisiting(false)
     , m_pNumberElement(nullptr)
     , m_nDictionaryOffset(0)
     , m_nDictionaryLength(0)


More information about the Libreoffice-commits mailing list