[poppler] poppler/Parser.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Nov 7 21:49:14 UTC 2018


 poppler/Parser.cc |   36 +++++++++++++++++++++---------------
 1 file changed, 21 insertions(+), 15 deletions(-)

New commits:
commit 178fdef48c18dfdb2f1efea780ffd320631defcd
Author: Albert Astals Cid <aacid at kde.org>
Date:   Sat Nov 3 21:04:52 2018 +0100

    Rework Parser::makeStream "entry" variable handling
    
    Scopes the entry variable so people don't try to use it in between

diff --git a/poppler/Parser.cc b/poppler/Parser.cc
index 2cf2bd12..311f2203 100644
--- a/poppler/Parser.cc
+++ b/poppler/Parser.cc
@@ -198,16 +198,19 @@ Stream *Parser::makeStream(Object &&dict, Guchar *fileKey,
   Stream *str;
   Goffset length;
   Goffset pos, endPos;
-  XRefEntry *entry = nullptr;
 
-  if (xref && (entry = xref->getEntry(objNum, false))) {
-    if (!entry->getFlag(XRefEntry::Parsing) ||
-        (objNum == 0 && objGen == 0)) {
-      entry->setFlag(XRefEntry::Parsing, true);
-    } else {
-      error(errSyntaxError, getPos(),
-            "Object '{0:d} {1:d} obj' is being already parsed", objNum, objGen);
-      return nullptr;
+
+  if (xref) {
+    XRefEntry *entry = xref->getEntry(objNum, false);
+    if (entry) {
+      if (!entry->getFlag(XRefEntry::Parsing) ||
+	  (objNum == 0 && objGen == 0)) {
+	entry->setFlag(XRefEntry::Parsing, true);
+      } else {
+	error(errSyntaxError, getPos(),
+	      "Object '{0:d} {1:d} obj' is being already parsed", objNum, objGen);
+	return nullptr;
+      }
     }
   }
 
@@ -230,10 +233,6 @@ Stream *Parser::makeStream(Object &&dict, Guchar *fileKey,
     length = 0;
   }
 
-  // the above dictLookup can cause a xref reconstruction if the file is damaged
-  // so we need to update the entry pointer
-  entry = xref ? xref->getEntry(objNum, false) : nullptr;
-
   // check for length in damaged file
   if (xref && xref->getStreamEnd(pos, &endPos)) {
     length = endPos - pos;
@@ -295,8 +294,15 @@ Stream *Parser::makeStream(Object &&dict, Guchar *fileKey,
   // get filters
   str = str->addFilters(str->getDict(), recursion);
 
-  if (entry)
-    entry->setFlag(XRefEntry::Parsing, false);
+  if (xref) {
+    // Don't try to reuse the entry from the block at the start
+    // of the function, xref can change in the middle because of
+    // reconstruction
+    XRefEntry *entry = xref->getEntry(objNum, false);
+    if (entry) {
+      entry->setFlag(XRefEntry::Parsing, false);
+    }
+  }
 
   return str;
 }


More information about the poppler mailing list