From 8051f678b3b43326e5fdfd7c03f39de21059f426 Mon Sep 17 00:00:00 2001
From: Albert Astals Cid <aacid@kde.org>
Date: Fri, 5 Apr 2019 16:34:48 +0200
Subject: [PATCH] FontInfoScanner::scanFonts Fix infinite loop in broken files
 
Fixes #752
---
 poppler/FontInfo.cc | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
 
diff --git a/poppler/FontInfo.cc b/poppler/FontInfo.cc
index 2c3be4c6..cd335771 100644
--- a/poppler/FontInfo.cc
+++ b/poppler/FontInfo.cc
@@ -144,7 +144,17 @@ void FontInfoScanner::scanFonts(XRef *xrefA, Dict *resDict, std::vector<FontInfo
 
         Object obj2 = obj1.fetch(xrefA);
         if (obj2.isStream()) {
-          Object resObj = obj2.streamGetDict()->lookup("Resources");
+          Ref resourcesRef;
+          const Object resObj = obj2.streamGetDict()->lookup("Resources");
+
+          if (resourcesRef.num != -1) {
+            if (visitedObjects.find(resourcesRef.num) != visitedObjects.end()) {
+              continue;
+            }
+
+            visitedObjects.insert(resourcesRef.num);
+          }
+
           if (resObj.isDict() && resObj.getDict() != resDict) {
             scanFonts(xrefA, resObj.getDict(), fontsList);
           }
-- 
2.20.1
