[poppler] 3 commits - poppler/Page.cc poppler/PDFDoc.cc poppler/XRef.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Mar 24 09:22:34 UTC 2023


 poppler/PDFDoc.cc |    6 +++---
 poppler/Page.cc   |    4 +++-
 poppler/XRef.cc   |    3 +++
 3 files changed, 9 insertions(+), 4 deletions(-)

New commits:
commit d07818d63677ccd2ea68b580ee45085597681a36
Author: Albert Astals Cid <aacid at kde.org>
Date:   Thu Mar 23 19:22:21 2023 +0100

    Page::removeAnnot: Reorder code to fix memory leak
    
    We were removing the annot object from the xref, then calling removeReferencedObjects
    that in some cases calls setModifiedObject on the xref with that same
    annot object, which is wrong, we can't modify an object that isn't there
    anymore

diff --git a/poppler/Page.cc b/poppler/Page.cc
index c256d391..83a4d88e 100644
--- a/poppler/Page.cc
+++ b/poppler/Page.cc
@@ -490,7 +490,6 @@ void Page::removeAnnot(Annot *annot)
         }
         annots->removeAnnot(annot); // Gracefully fails on popup windows
         annArray.arrayRemove(idx);
-        xref->removeIndirectObject(annotRef);
 
         if (annotsObj.isRef()) {
             xref->setModifiedObject(&annArray, annotsObj.getRef());
@@ -499,6 +498,9 @@ void Page::removeAnnot(Annot *annot)
         }
     }
     annot->removeReferencedObjects(); // Note: Might recurse in removeAnnot again
+    if (annArray.isArray()) {
+        xref->removeIndirectObject(annotRef);
+    }
     annot->setPage(0, false);
 }
 
commit 96a953dbde5339798ca583a5ced2e6f0384351e7
Author: Albert Astals Cid <aacid at kde.org>
Date:   Thu Mar 23 19:21:16 2023 +0100

    XRef: Add a warning if calling setModifiedObject on empty ref

diff --git a/poppler/XRef.cc b/poppler/XRef.cc
index 601ecd6a..08706623 100644
--- a/poppler/XRef.cc
+++ b/poppler/XRef.cc
@@ -1425,6 +1425,9 @@ void XRef::setModifiedObject(const Object *o, Ref r)
         return;
     }
     XRefEntry *e = getEntry(r.num);
+    if (unlikely(e->type == xrefEntryFree)) {
+        error(errInternal, -1, "XRef::setModifiedObject on ref: {0:d}, {1:d} that is marked as free. This will cause a memory leak\n", r.num, r.gen);
+    }
     e->obj = o->copy();
     e->setFlag(XRefEntry::Updated, true);
     setModified();
commit ea5e64f139094ec93b2261d51a61c8a8b9b57e44
Author: Albert Astals Cid <aacid at kde.org>
Date:   Fri Mar 17 00:14:56 2023 +0100

    PDFDoc::sign: Fix memory issue when signing fails
    
    Issue #1372

diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index a81d5908..f1b9bfcb 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -2218,14 +2218,14 @@ bool PDFDoc::sign(const std::string &saveFilename, const std::string &certNickna
     form->ensureFontsForAllCharacters(&signatureText, pdfFontName);
     form->ensureFontsForAllCharacters(&signatureTextLeft, pdfFontName);
 
-    std::unique_ptr<::FormFieldSignature> field = std::make_unique<::FormFieldSignature>(this, Object(annotObj.getDict()), ref, nullptr, nullptr);
+    std::unique_ptr<::FormFieldSignature> field = std::make_unique<::FormFieldSignature>(this, std::move(annotObj), ref, nullptr, nullptr);
     field->setCustomAppearanceContent(signatureText);
     field->setCustomAppearanceLeftContent(signatureTextLeft);
     field->setCustomAppearanceLeftFontSize(leftFontSize);
     field->setImageResource(imageResourceRef);
 
     Object refObj(ref);
-    AnnotWidget *signatureAnnot = new AnnotWidget(this, &annotObj, &refObj, field.get());
+    AnnotWidget *signatureAnnot = new AnnotWidget(this, field->getObj(), &refObj, field.get());
     signatureAnnot->setFlags(signatureAnnot->getFlags() | Annot::flagPrint | Annot::flagLocked | Annot::flagNoRotate);
     Dict dummy(getXRef());
     auto appearCharacs = std::make_unique<AnnotAppearanceCharacs>(&dummy);
@@ -2251,7 +2251,7 @@ bool PDFDoc::sign(const std::string &saveFilename, const std::string &certNickna
 
         // Now remove the signature stuff in case the user wants to continue editing stuff
         // So the document object is clean
-        const Object &vRefObj = annotObj.dictLookupNF("V");
+        const Object &vRefObj = field->getObj()->dictLookupNF("V");
         if (vRefObj.isRef()) {
             getXRef()->removeIndirectObject(vRefObj.getRef());
         }


More information about the poppler mailing list