[Pkg-javascript-commits] [pdf.js] 02/119: Avoid getting stuck in empty nodes in the Pages tree when calling |Catalog_getPageDict| (issue 5644)

David Prévot taffit at moszumanska.debian.org
Wed May 13 21:27:35 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 888cbe0bde3bdfec0b0a08f5aa0158380368708f
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Sat Jan 17 12:53:32 2015 +0100

    Avoid getting stuck in empty nodes in the Pages tree when calling |Catalog_getPageDict| (issue 5644)
---
 src/core/obj.js              | 12 +++++++++---
 test/pdfs/issue5644.pdf.link |  1 +
 test/test_manifest.json      |  9 +++++++++
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/core/obj.js b/src/core/obj.js
index babfdaf..5687b8a 100644
--- a/src/core/obj.js
+++ b/src/core/obj.js
@@ -597,6 +597,7 @@ var Catalog = (function CatalogClosure() {
       var nodesToVisit = [this.catDict.getRaw('Pages')];
       var currentPageIndex = 0;
       var xref = this.xref;
+      var checkAllKids = false;
 
       function next() {
         while (nodesToVisit.length) {
@@ -604,7 +605,7 @@ var Catalog = (function CatalogClosure() {
 
           if (isRef(currentNode)) {
             xref.fetchAsync(currentNode).then(function (obj) {
-              if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
+              if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
                 if (pageIndex === currentPageIndex) {
                   capability.resolve([obj, currentNode]);
                 } else {
@@ -619,12 +620,17 @@ var Catalog = (function CatalogClosure() {
             return;
           }
 
-          // must be a child page dictionary
+          // Must be a child page dictionary.
           assert(
             isDict(currentNode),
             'page dictionary kid reference points to wrong type of object'
           );
           var count = currentNode.get('Count');
+          // If the current node doesn't have any children, avoid getting stuck
+          // in an empty node further down in the tree (see issue5644.pdf).
+          if (count === 0) {
+            checkAllKids = true;
+          }
           // Skip nodes where the page can't be.
           if (currentPageIndex + count <= pageIndex) {
             currentPageIndex += count;
@@ -633,7 +639,7 @@ var Catalog = (function CatalogClosure() {
 
           var kids = currentNode.get('Kids');
           assert(isArray(kids), 'page dictionary kids object is not an array');
-          if (count === kids.length) {
+          if (!checkAllKids && count === kids.length) {
             // Nodes that don't have the page have been skipped and this is the
             // bottom of the tree which means the page requested must be a
             // descendant of this pages node. Ideally we would just resolve the
diff --git a/test/pdfs/issue5644.pdf.link b/test/pdfs/issue5644.pdf.link
new file mode 100644
index 0000000..fe447e6
--- /dev/null
+++ b/test/pdfs/issue5644.pdf.link
@@ -0,0 +1 @@
+http://web.archive.org/web/20140703204310/http://repository.readscheme.org/ftp/papers/sw2010/06-barland.pdf
diff --git a/test/test_manifest.json b/test/test_manifest.json
index 9332d52..82270d5 100644
--- a/test/test_manifest.json
+++ b/test/test_manifest.json
@@ -812,6 +812,15 @@
        "link": false,
        "type": "eq"
     },
+    {  "id": "issue5644",
+       "file": "pdfs/issue5644.pdf",
+       "md5": "6f9313c5043b3ecb0ab2df321d3e1847",
+       "rounds": 1,
+       "link": true,
+       "firstPage": 1,
+       "lastPage": 6,
+       "type": "eq"
+    },
     {  "id": "bug866395",
        "file": "pdfs/bug866395.pdf",
        "md5": "f03bc77e84637241980b09a0a220f575",

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list