]> git.parisson.com Git - pdf.js.git/commitdiff
Don't check gen number for free entry; don't index objects twice
authorYury Delendik <ydelendik@mozilla.com>
Tue, 24 Apr 2012 03:14:58 +0000 (22:14 -0500)
committerYury Delendik <ydelendik@mozilla.com>
Tue, 24 Apr 2012 03:14:58 +0000 (22:14 -0500)
src/obj.js
test/pdfs/issue1586.pdf.link [new file with mode: 0644]
test/test_manifest.json

index c905a7dc5c2718cb2b7369580dd25160b427005e..47aed8f8a7a553f0c8a40720800aa58b371de041 100644 (file)
@@ -364,9 +364,8 @@ var XRef = (function XRefClosure() {
         }
       }
 
-      // Sanity check: as per spec, first object must have these properties
-      if (this.entries[0] &&
-          !(this.entries[0].gen === 65535 && this.entries[0].free))
+      // Sanity check: as per spec, first object must be free
+      if (this.entries[0] && !this.entries[0].free)
         error('Invalid XRef table: unexpected first object');
 
       // Sanity check
@@ -525,7 +524,7 @@ var XRef = (function XRefClosure() {
       }
       // reading XRef streams
       for (var i = 0, ii = xrefStms.length; i < ii; ++i) {
-          this.readXRef(xrefStms[i]);
+          this.readXRef(xrefStms[i], true);
       }
       // finding main trailer
       var dict;
@@ -548,7 +547,7 @@ var XRef = (function XRefClosure() {
       // nothing helps
       error('Invalid PDF structure');
     },
-    readXRef: function XRef_readXRef(startXRef) {
+    readXRef: function XRef_readXRef(startXRef, recoveryMode) {
       var stream = this.stream;
       stream.pos = startXRef;
 
@@ -581,16 +580,18 @@ var XRef = (function XRefClosure() {
             error('Invalid XRef stream');
           }
           dict = this.readXRefStream(obj);
+          if (!dict)
+            error('Failed to read XRef stream');
         }
 
         // Recursively get previous dictionary, if any
         obj = dict.get('Prev');
         if (isInt(obj))
-          this.readXRef(obj);
+          this.readXRef(obj, recoveryMode);
         else if (isRef(obj)) {
           // The spec says Prev must not be a reference, i.e. "/Prev NNN"
           // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
-          this.readXRef(obj.num);
+          this.readXRef(obj.num, recoveryMode);
         }
 
         return dict;
@@ -598,6 +599,9 @@ var XRef = (function XRefClosure() {
         log('(while reading XRef): ' + e);
       }
 
+      if (recoveryMode)
+        return;
+
       warn('Indexing all PDF objects');
       return this.indexObjects();
     },
diff --git a/test/pdfs/issue1586.pdf.link b/test/pdfs/issue1586.pdf.link
new file mode 100644 (file)
index 0000000..f66f7f3
--- /dev/null
@@ -0,0 +1 @@
+http://cdn.flamehaus.com/Valve_Handbook_LowRes.pdf
index 207c41c22a64ef27ed9bd9f641ba25df1e2e7e0e..1dd1f6c1e6061c5c849744851b4c48c503c8dd85 100644 (file)
       "link": true,
       "type": "eq"
     },
+    {  "id": "issue1586",
+      "file": "pdfs/issue1586.pdf",
+      "md5": "80d396cb306014b24ca82ceb68958fb5",
+      "rounds": 1,
+      "link": true,
+      "type": "load"
+    },
     {  "id": "aboutstacks",
       "file": "pdfs/aboutstacks.pdf",
       "md5": "6e7c8416a293ba2d83bc8dd20c6ccf51",