[Pkg-javascript-commits] [pdf.js] 54/414: Better crypto key length recovery.

David Prévot taffit at moszumanska.debian.org
Tue Jun 28 17:12:05 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 c991480687477b9574e1d92c1c9dd33627c948ea
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Tue Dec 29 15:10:38 2015 -0600

    Better crypto key length recovery.
---
 src/core/crypto.js           | 23 ++++++++++++++++++++++-
 test/pdfs/bug951051.pdf.link |  1 +
 test/test_manifest.json      |  8 ++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/core/crypto.js b/src/core/crypto.js
index 7a9efb7..7fc60dd 100644
--- a/src/core/crypto.js
+++ b/src/core/crypto.js
@@ -38,6 +38,7 @@ var utf8StringToString = sharedUtil.utf8StringToString;
 var warn = sharedUtil.warn;
 var Name = corePrimitives.Name;
 var isName = corePrimitives.isName;
+var isDict = corePrimitives.isDict;
 var DecryptStream = coreStream.DecryptStream;
 
 var ARCFourCipher = (function ARCFourCipherClosure() {
@@ -1921,7 +1922,27 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {
       error('unsupported encryption algorithm');
     }
     this.algorithm = algorithm;
-    var keyLength = dict.get('Length') || 40;
+    var keyLength = dict.get('Length');
+    if (!keyLength) {
+      // Spec asks to rely on encryption dictionary's Length entry, however
+      // some PDFs don't have it. Trying to recover.
+      if (algorithm <= 3) {
+        // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
+        keyLength = 40;
+      } else {
+        // Trying to find default handler -- it usually has Length.
+        var cfDict = dict.get('CF');
+        var streamCryptoName = dict.get('StmF');
+        if (isDict(cfDict) && isName(streamCryptoName)) {
+          var handlerDict = cfDict.get(streamCryptoName.name);
+          keyLength = (handlerDict && handlerDict.get('Length')) || 128;
+          if (keyLength < 40) {
+            // Sometimes it's incorrect value of bits, generators specify bytes.
+            keyLength <<= 3;
+          }
+        }
+      }
+    }
     if (!isInt(keyLength) ||
         keyLength < 40 || (keyLength % 8) !== 0) {
       error('invalid key length');
diff --git a/test/pdfs/bug951051.pdf.link b/test/pdfs/bug951051.pdf.link
new file mode 100644
index 0000000..7cf865a
--- /dev/null
+++ b/test/pdfs/bug951051.pdf.link
@@ -0,0 +1 @@
+http://web.archive.org/web/20120618235740/http://www.intreprinzatorturism.ro/wp-content/uploads/2012/05/ITPR-studiu-online-5000-turisti-straini_martie-2012.pdf
diff --git a/test/test_manifest.json b/test/test_manifest.json
index 92d433d..d67a266 100644
--- a/test/test_manifest.json
+++ b/test/test_manifest.json
@@ -2000,6 +2000,14 @@
       "link": true,
       "type": "eq"
     },
+    {  "id": "bug951051",
+      "file": "pdfs/bug951051.pdf",
+      "md5": "05d325a5112bd3f6022367dab7bc07b9",
+      "rounds": 1,
+      "lastPage": 1,
+      "link": true,
+      "type": "load"
+    },
     {  "id": "issue3062",
       "file": "pdfs/issue3062.pdf",
       "md5": "206715f1258f0e117df4180d98dd4d68",

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