From 16c35d5f018d654a8ecf8989a17aba2aa67ef353 Mon Sep 17 00:00:00 2001 From: Jakub Melka Date: Sun, 6 Aug 2023 17:10:03 +0200 Subject: [PATCH] Issue #77: Document read error --- Pdf4QtLib/sources/pdfoutline.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Pdf4QtLib/sources/pdfoutline.cpp b/Pdf4QtLib/sources/pdfoutline.cpp index ed7155c..e88f4ad 100644 --- a/Pdf4QtLib/sources/pdfoutline.cpp +++ b/Pdf4QtLib/sources/pdfoutline.cpp @@ -65,12 +65,17 @@ void PDFOutlineItem::parseImpl(const PDFObjectStorage* storage, { if (visitedOutlineItems.count(reference)) { - throw PDFException(PDFTranslationContext::tr("Outline items have cyclic dependence.")); + return false; } visitedOutlineItems.insert(reference); + return true; }; - checkCyclicDependence(currentItem); + + if (!checkCyclicDependence(currentItem)) + { + return; + } PDFObject dereferencedItem = storage->getObjectByReference(currentItem); while (dereferencedItem.isDictionary()) @@ -106,7 +111,8 @@ void PDFOutlineItem::parseImpl(const PDFObjectStorage* storage, const PDFObject& firstItem = dictionary->get("First"); if (firstItem.isReference()) { - parseImpl(storage, currentOutlineItem.get(), firstItem.getReference(), visitedOutlineItems); + std::set currentVisitedOutlineItems = visitedOutlineItems; + parseImpl(storage, currentOutlineItem.get(), firstItem.getReference(), currentVisitedOutlineItems); } // Add new child to the parent @@ -116,7 +122,10 @@ void PDFOutlineItem::parseImpl(const PDFObjectStorage* storage, const PDFObject& nextItem = dictionary->get("Next"); if (nextItem.isReference()) { - checkCyclicDependence(nextItem.getReference()); + if (!checkCyclicDependence(nextItem.getReference())) + { + break; + } dereferencedItem = storage->getObject(nextItem); } else