From 94da20d77653b41142b836e7aa045429f438053a Mon Sep 17 00:00:00 2001
From: notmasteryet <async.processingjs@yahoo.com>
Date: Tue, 13 Sep 2011 19:23:49 -0500
Subject: [PATCH] Disable encryption when a ToUnicode stream is used in a font

---
 pdf.js                      | 9 ++++++---
 test/pdfs/artofwar.pdf.link | 1 +
 test/test_manifest.json     | 6 ++++++
 3 files changed, 13 insertions(+), 3 deletions(-)
 create mode 100644 test/pdfs/artofwar.pdf.link

diff --git a/pdf.js b/pdf.js
index 939d9e21c..019961f15 100644
--- a/pdf.js
+++ b/pdf.js
@@ -3185,7 +3185,7 @@ var XRef = (function() {
         return obj;
       return this.fetch(obj);
     },
-    fetch: function(ref) {
+    fetch: function(ref, suppressEncryption) {
       var num = ref.num;
       var e = this.cache[num];
       if (e)
@@ -3216,7 +3216,7 @@ var XRef = (function() {
           }
           error('bad XRef entry');
         }
-        if (this.encrypt) {
+        if (this.encrypt && !suppressEncryption) {
           e = parser.getObj(this.encrypt.createCipherTransform(num, gen));
         } else {
           e = parser.getObj();
@@ -4356,7 +4356,10 @@ var PartialEvaluator = (function() {
       }
 
       if (type == 'TrueType' && dict.has('ToUnicode') && differences) {
-        var cmapObj = xref.fetchIfRef(dict.get('ToUnicode'));
+        var cmapObj = dict.get('ToUnicode');
+        if (IsRef(cmapObj)) {
+          cmapObj = xref.fetch(cmapObj, true);
+        }
         if (IsName(cmapObj)) {
           error('ToUnicode file cmap translation not implemented');
         } else if (IsStream(cmapObj)) {
diff --git a/test/pdfs/artofwar.pdf.link b/test/pdfs/artofwar.pdf.link
new file mode 100644
index 000000000..f70b9e235
--- /dev/null
+++ b/test/pdfs/artofwar.pdf.link
@@ -0,0 +1 @@
+http://www.puppetpress.com/classics/ArtofWarbySunTzu.pdf
diff --git a/test/test_manifest.json b/test/test_manifest.json
index 1155195cb..3734ee9e4 100644
--- a/test/test_manifest.json
+++ b/test/test_manifest.json
@@ -109,5 +109,11 @@
        "link": true,
        "rounds": 1,
        "type": "eq"
+    },
+    {  "id": "artofwar",
+       "file": "pdfs/artofwar.pdf",
+       "link": true,
+       "rounds": 1,
+       "type": "eq"
     }
 ]