[poppler] poppler/Outline.cc poppler/Outline.h
Albert Astals Cid
aacid at kemper.freedesktop.org
Tue Dec 26 23:19:36 UTC 2017
poppler/Outline.cc | 31 +++++++++++++++++--------------
poppler/Outline.h | 6 ++++--
2 files changed, 21 insertions(+), 16 deletions(-)
New commits:
commit e41ce80a27b735df8e2ccc17e15adea012543712
Author: Albert Astals Cid <aacid at kde.org>
Date: Wed Dec 27 00:18:47 2017 +0100
OutlineItem: Store parent and refNum
This way when opening our children we make sure they are not also our
parent (i.e. there's a loop)
Fixes bug #102914
diff --git a/poppler/Outline.cc b/poppler/Outline.cc
index 82f28663..bd32ec0b 100644
--- a/poppler/Outline.cc
+++ b/poppler/Outline.cc
@@ -47,7 +47,7 @@ Outline::Outline(Object *outlineObj, XRef *xref) {
return;
}
Object first = outlineObj->dictLookupNF("First");
- items = OutlineItem::readItemList(&first, xref);
+ items = OutlineItem::readItemList(nullptr, &first, xref);
}
Outline::~Outline() {
@@ -58,9 +58,11 @@ Outline::~Outline() {
//------------------------------------------------------------------------
-OutlineItem::OutlineItem(Dict *dict, XRef *xrefA) {
+OutlineItem::OutlineItem(Dict *dict, int refNumA, OutlineItem *parentA, XRef *xrefA) {
Object obj1;
+ refNum = refNumA;
+ parent = parentA;
xref = xrefA;
title = NULL;
action = NULL;
@@ -108,28 +110,29 @@ OutlineItem::~OutlineItem() {
}
}
-GooList *OutlineItem::readItemList(Object *firstItemRef, XRef *xrefA) {
- GooList *items;
- char* alreadyRead;
- OutlineItem *item;
- Object *p;
+GooList *OutlineItem::readItemList(OutlineItem *parent, Object *firstItemRef, XRef *xrefA) {
+ GooList *items = new GooList();
- items = new GooList();
-
- alreadyRead = (char *)gmalloc(xrefA->getNumObjects());
+ char* alreadyRead = (char *)gmalloc(xrefA->getNumObjects());
memset(alreadyRead, 0, xrefA->getNumObjects());
- p = firstItemRef;
+ OutlineItem *parentO = parent;
+ while (parentO) {
+ alreadyRead[parentO->refNum] = 1;
+ parentO = parentO->parent;
+ }
+
+ Object *p = firstItemRef;
while (p->isRef() &&
(p->getRefNum() >= 0) &&
- (p->getRefNum() < xrefA->getNumObjects()) &&
+ (p->getRefNum() < xrefA->getNumObjects()) &&
!alreadyRead[p->getRefNum()]) {
Object obj = p->fetch(xrefA);
if (!obj.isDict()) {
break;
}
alreadyRead[p->getRefNum()] = 1;
- item = new OutlineItem(obj.getDict(), xrefA);
+ OutlineItem *item = new OutlineItem(obj.getDict(), p->getRefNum(), parent, xrefA);
items->append(item);
p = &item->nextRef;
}
@@ -146,7 +149,7 @@ GooList *OutlineItem::readItemList(Object *firstItemRef, XRef *xrefA) {
void OutlineItem::open() {
if (!kids) {
- kids = readItemList(&firstRef, xref);
+ kids = readItemList(this, &firstRef, xref);
}
}
diff --git a/poppler/Outline.h b/poppler/Outline.h
index 46775d59..1585d0e4 100644
--- a/poppler/Outline.h
+++ b/poppler/Outline.h
@@ -57,10 +57,10 @@ private:
class OutlineItem {
public:
- OutlineItem(Dict *dict, XRef *xrefA);
+ OutlineItem(Dict *dict, int refNumA, OutlineItem *parentA, XRef *xrefA);
~OutlineItem();
- static GooList *readItemList(Object *firstItemRef, XRef *xrefA);
+ static GooList *readItemList(OutlineItem *parent, Object *firstItemRef, XRef *xrefA);
void open();
void close();
@@ -74,6 +74,8 @@ public:
private:
+ int refNum;
+ OutlineItem *parent;
XRef *xref;
Unicode *title;
int titleLen;
More information about the poppler
mailing list