[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/KDE/3.5/kdegraphics/kpdf/xpdf/xpdf
From:       Albert Astals Cid <tsdgeos () terra ! es>
Date:       2007-01-11 21:50:38
Message-ID: 1168552238.067450.22778.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 622461 by aacid:

Less complete but equally effective and more quick way of fixing the MOAB-06-01-2007 \
problem.


 M  +0 -2      Array.h  
 M  +14 -15    Catalog.cc  
 M  +1 -3      Catalog.h  


--- branches/KDE/3.5/kdegraphics/kpdf/xpdf/xpdf/Array.h #622460:622461
@@ -47,8 +47,6 @@
   Object *getNF(int i, Object *obj);
   GBool getString(int i, GString *string);
 
-  XRef *getXRef() { return xref; }
-
 private:
 
   XRef *xref;			// the xref table for this PDF file
--- branches/KDE/3.5/kdegraphics/kpdf/xpdf/xpdf/Catalog.cc #622460:622461
@@ -26,6 +26,12 @@
 #include "UGString.h"
 #include "Catalog.h"
 
+// This define is used to limit the depth of recursive readPageTree calls
+// This is needed because the page tree nodes can reference their parents
+// leaving us in an infinite loop
+// Most sane pdf documents don't have a call depth higher than 10
+#define MAX_CALL_DEPTH 1000
+
 //------------------------------------------------------------------------
 // Catalog
 //------------------------------------------------------------------------
@@ -35,7 +41,6 @@
   Object obj, obj2;
   int numPages0;
   int i;
-  std::set< std::pair<int, int> > readNodes;
 
   ok = gTrue;
   xref = xrefA;
@@ -52,9 +57,7 @@
   }
 
   // read page tree
-  catDict.dictLookupNF("Pages", &pagesDict);
-  readNodes.insert( std::pair<int, int>(pagesDict.getRef().num, \
                pagesDict.getRef().gen) );
-  pagesDict.fetch(xref, &pagesDict);
+  catDict.dictLookup("Pages", &pagesDict);
   // This should really be isDict("Pages"), but I've seen at least one
   // PDF file where the /Type entry is missing.
   if (!pagesDict.isDict()) {
@@ -79,7 +82,7 @@
     pageRefs[i].num = -1;
     pageRefs[i].gen = -1;
   }
-  numPages = readPageTree(pagesDict.getDict(), NULL, 0, readNodes);
+  numPages = readPageTree(pagesDict.getDict(), NULL, 0, 0);
   if (numPages != numPages0) {
     error(-1, "Page count in top-level pages object is incorrect");
   }
@@ -194,7 +197,7 @@
   return s;
 }
 
-int Catalog::readPageTree(Dict *pagesDict, PageAttrs *attrs, int start, std::set< \
std::pair<int, int> > &readNodes) { +int Catalog::readPageTree(Dict *pagesDict, \
PageAttrs *attrs, int start, int callDepth) {  Object kids;
   Object kid;
   Object kidRef;
@@ -210,9 +213,7 @@
     goto err1;
   }
   for (i = 0; i < kids.arrayGetLength(); ++i) {
-    kids.arrayGetNF(i, &kid);
-    const Ref &ref = kid.getRef();
-    kid.fetch(kids.getArray()->getXRef(), &kid);
+    kids.arrayGet(i, &kid);
     if (kid.isDict("Page")) {
       attrs2 = new PageAttrs(attrs1, kid.getDict());
       page = new Page(xref, start+1, kid.getDict(), attrs2);
@@ -241,14 +242,12 @@
     // This should really be isDict("Pages"), but I've seen at least one
     // PDF file where the /Type entry is missing.
     } else if (kid.isDict()) {
-      std::pair<int, int> node(ref.num, ref.gen);
-      std::pair< std::set< std::pair<int, int> >::iterator, bool> insertResult = \
                readNodes.insert(node);
-      if (insertResult.second) {
-        if ((start = readPageTree(kid.getDict(), attrs1, start, readNodes))
+      if (callDepth > MAX_CALL_DEPTH) {
+        error(-1, "Limit of %d recursive calls reached while reading the page tree. \
If your document is correct and not a test to try to force a crash, please report a \
bug.", MAX_CALL_DEPTH); +      } else {
+        if ((start = readPageTree(kid.getDict(), attrs1, start, callDepth + 1))
 	    < 0)
 	  goto err2;
-      } else {
-       error(-1, "Kid object was already processed. The pdf is faulty.");
       }
     } else {
       error(-1, "Kid object (page %d) is wrong type (%s)",
--- branches/KDE/3.5/kdegraphics/kpdf/xpdf/xpdf/Catalog.h #622460:622461
@@ -11,8 +11,6 @@
 
 #include <aconf.h>
 
-#include <set>
-
 #ifdef USE_GCC_PRAGMAS
 #pragma interface
 #endif
@@ -130,7 +128,7 @@
   Object acroForm;		// AcroForm dictionary
   GBool ok;			// true if catalog is valid
 
-  int readPageTree(Dict *pages, PageAttrs *attrs, int start, std::set< \
std::pair<int, int> > &readNodes); +  int readPageTree(Dict *pages, PageAttrs *attrs, \
int start, int callDepth);  Object *findDestInTree(Object *tree, GString *name, \
Object *obj);  };
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic