summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbert Astals Cid <aacid@kde.org>2023-09-26 22:55:30 +0200
committerAlbert Astals Cid <aacid@kde.org>2023-09-26 20:56:14 +0000
commitbbf225296bcb698713fda0d144e9d86ea2e28c55 (patch)
tree1fab3e46fc437ae646d7a61bdfb9e13ae65c5e57
parent1f8500587a5970879ddc282d0ae041991db6e6a6 (diff)
Use RefRecursionChecker in StructElement
-rw-r--r--poppler/StructElement.cc11
-rw-r--r--poppler/StructElement.h8
-rw-r--r--poppler/StructTreeRoot.cc6
3 files changed, 12 insertions, 13 deletions
diff --git a/poppler/StructElement.cc b/poppler/StructElement.cc
index 0808ce90..9b722c19 100644
--- a/poppler/StructElement.cc
+++ b/poppler/StructElement.cc
@@ -6,7 +6,7 @@
//
// Copyright 2013, 2014 Igalia S.L.
// Copyright 2014 Luigi Scarso <luigi.scarso@gmail.com>
-// Copyright 2014, 2017-2019, 2021 Albert Astals Cid <aacid@kde.org>
+// Copyright 2014, 2017-2019, 2021, 2023 Albert Astals Cid <aacid@kde.org>
// Copyright 2015 Dmytro Morgun <lztoad@gmail.com>
// Copyright 2018, 2021 Adrian Johnson <ajohnson@redneon.com>
// Copyright 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
@@ -712,7 +712,7 @@ StructElement::StructData::~StructData()
}
}
-StructElement::StructElement(Dict *element, StructTreeRoot *treeRootA, StructElement *parentA, std::set<int> &seen) : type(Unknown), treeRoot(treeRootA), parent(parentA), s(new StructData())
+StructElement::StructElement(Dict *element, StructTreeRoot *treeRootA, StructElement *parentA, RefRecursionChecker &seen) : type(Unknown), treeRoot(treeRootA), parent(parentA), s(new StructData())
{
assert(treeRoot);
assert(element);
@@ -1055,7 +1055,7 @@ void StructElement::parse(Dict *element)
}
}
-StructElement *StructElement::parseChild(const Object *ref, Object *childObj, std::set<int> &seen)
+StructElement *StructElement::parseChild(const Object *ref, Object *childObj, RefRecursionChecker &seen)
{
assert(childObj);
assert(ref);
@@ -1107,8 +1107,7 @@ StructElement *StructElement::parseChild(const Object *ref, Object *childObj, st
} else if (childObj->isDict()) {
if (!ref->isRef()) {
error(errSyntaxError, -1, "Structure element dictionary is not an indirect reference ({0:s})", ref->getTypeName());
- } else if (seen.find(ref->getRefNum()) == seen.end()) {
- seen.insert(ref->getRefNum());
+ } else if (seen.insert(ref->getRef())) {
child = new StructElement(childObj->getDict(), treeRoot, this, seen);
} else {
error(errSyntaxWarning, -1, "Loop detected in structure tree, skipping subtree at object {0:d}:{1:d}", ref->getRefNum(), ref->getRefGen());
@@ -1132,7 +1131,7 @@ StructElement *StructElement::parseChild(const Object *ref, Object *childObj, st
return child;
}
-void StructElement::parseChildren(Dict *element, std::set<int> &seen)
+void StructElement::parseChildren(Dict *element, RefRecursionChecker &seen)
{
Object kids = element->lookup("K");
if (kids.isArray()) {
diff --git a/poppler/StructElement.h b/poppler/StructElement.h
index 7369055c..2244fbe2 100644
--- a/poppler/StructElement.h
+++ b/poppler/StructElement.h
@@ -6,7 +6,7 @@
//
// Copyright 2013, 2014 Igalia S.L.
// Copyright 2014 Luigi Scarso <luigi.scarso@gmail.com>
-// Copyright 2014, 2018, 2019, 2021 Albert Astals Cid <aacid@kde.org>
+// Copyright 2014, 2018, 2019, 2021, 2023 Albert Astals Cid <aacid@kde.org>
// Copyright 2018 Adam Reichold <adam.reichold@t-online.de>
// Copyright 2021 Adrian Johnson <ajohnson@redneon.com>
//
@@ -391,13 +391,13 @@ private:
ContentData *c;
};
- StructElement(Dict *elementDict, StructTreeRoot *treeRootA, StructElement *parentA, std::set<int> &seen);
+ StructElement(Dict *elementDict, StructTreeRoot *treeRootA, StructElement *parentA, RefRecursionChecker &seen);
StructElement(int mcid, StructTreeRoot *treeRootA, StructElement *parentA);
StructElement(const Ref ref, StructTreeRoot *treeRootA, StructElement *parentA);
void parse(Dict *elementDict);
- StructElement *parseChild(const Object *ref, Object *childObj, std::set<int> &seen);
- void parseChildren(Dict *element, std::set<int> &seen);
+ StructElement *parseChild(const Object *ref, Object *childObj, RefRecursionChecker &seen);
+ void parseChildren(Dict *element, RefRecursionChecker &seen);
void parseAttributes(Dict *attributes, bool keepExisting = false);
friend class StructTreeRoot;
diff --git a/poppler/StructTreeRoot.cc b/poppler/StructTreeRoot.cc
index 47adac96..99ddbfe5 100644
--- a/poppler/StructTreeRoot.cc
+++ b/poppler/StructTreeRoot.cc
@@ -7,7 +7,7 @@
// Copyright 2013, 2014 Igalia S.L.
// Copyright 2014 Fabio D'Urso <fabiodurso@hotmail.it>
// Copyright 2017 Jan-Erik S <janerik234678@gmail.com>
-// Copyright 2017-2019 Albert Astals Cid <aacid@kde.org>
+// Copyright 2017-2019, 2023 Albert Astals Cid <aacid@kde.org>
// Copyright 2017, 2018 Adrian Johnson <ajohnson@redneon.com>
// Copyright 2018, Adam Reichold <adam.reichold@t-online.de>
//
@@ -54,7 +54,7 @@ void StructTreeRoot::parse(Dict *root)
parseNumberTreeNode(parentTreeObj.getDict());
}
- std::set<int> seenElements;
+ RefRecursionChecker seenElements;
// Parse the children StructElements
const bool marked = doc->getCatalog()->getMarkInfo() & Catalog::markInfoMarked;
@@ -66,7 +66,7 @@ void StructTreeRoot::parse(Dict *root)
for (int i = 0; i < kids.arrayGetLength(); i++) {
const Object &ref = kids.arrayGetNF(i);
if (ref.isRef()) {
- seenElements.insert(ref.getRefNum());
+ seenElements.insert(ref.getRef());
}
Object obj = kids.arrayGet(i);
if (obj.isDict()) {