[Pkg-javascript-commits] [pdf.js] 70/414: Check that CIDFontType0 fonts does not actually contain OpenType font files (issue 6782)

David Prévot taffit at moszumanska.debian.org
Tue Jun 28 17:12:07 UTC 2016


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

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

commit 896e390285f69e245161b5dac2e60ac86feb3827
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Wed Jan 6 02:07:21 2016 +0100

    Check that CIDFontType0 fonts does not actually contain OpenType font files (issue 6782)
    
    *This patch follows a similar idea as PR 5756.*
    
    The patch is based on the nice debugging done by Brendan in the referenced issue 6782.
    A better way to handle this, and similar issues, would probably be to completely ignore what the PDF file claims about font type/subtype, and just check the actual data. But until that kind of rewrite happens, this patch should help.
    
    Fixes 6782.
---
 src/core/fonts.js       |  14 +++++++++++++-
 test/pdfs/.gitignore    |   1 +
 test/pdfs/issue6782.pdf | Bin 0 -> 23181 bytes
 test/test_manifest.json |   7 +++++++
 4 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/core/fonts.js b/src/core/fonts.js
index 95ee7fd..cdb08c7 100644
--- a/src/core/fonts.js
+++ b/src/core/fonts.js
@@ -2666,7 +2666,14 @@ var Font = (function FontClosure() {
     }
     // Some CIDFontType0C fonts by mistake claim CIDFontType0.
     if (type === 'CIDFontType0') {
-      subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
+      if (isType1File(file)) {
+        subtype = 'CIDFontType0';
+      } else if (isOpenTypeFile(file)) {
+        // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
+        type = subtype = 'OpenType';
+      } else {
+        subtype = 'CIDFontType0C';
+      }
     }
 
     var data;
@@ -2750,6 +2757,11 @@ var Font = (function FontClosure() {
     return readUint32(header, 0) === 0x00010000;
   }
 
+  function isOpenTypeFile(file) {
+    var header = file.peekBytes(4);
+    return bytesToString(header) === 'OTTO';
+  }
+
   function isType1File(file) {
     var header = file.peekBytes(2);
     // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore
index 74aa953..e6b2b9c 100644
--- a/test/pdfs/.gitignore
+++ b/test/pdfs/.gitignore
@@ -14,6 +14,7 @@
 !issue5946.pdf
 !issue5972.pdf
 !issue5874.pdf
+!issue6782.pdf
 !filled-background.pdf
 !ArabicCIDTrueType.pdf
 !ThuluthFeatures.pdf
diff --git a/test/pdfs/issue6782.pdf b/test/pdfs/issue6782.pdf
new file mode 100644
index 0000000..d86458e
Binary files /dev/null and b/test/pdfs/issue6782.pdf differ
diff --git a/test/test_manifest.json b/test/test_manifest.json
index 6945092..1a14544 100644
--- a/test/test_manifest.json
+++ b/test/test_manifest.json
@@ -1472,6 +1472,13 @@
        "link": false,
        "type": "eq"
     },
+    {  "id": "issue6782",
+       "file": "pdfs/issue6782.pdf",
+       "md5": "b423f709600daa5745cc6d8234f7c608",
+       "rounds": 1,
+       "link": false,
+       "type": "eq"
+    },
     {  "id": "bug867484",
       "file": "pdfs/bug867484.pdf",
       "md5": "347af7b0ef7279b1a7f43b03bfda4548",

-- 
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