]> git.parisson.com Git - pdf.js.git/commitdiff
Fix arcfour initialization and encoding; png prediction fix
authornotmasteryet <async.processingjs@yahoo.com>
Sat, 25 Jun 2011 03:08:33 +0000 (22:08 -0500)
committernotmasteryet <async.processingjs@yahoo.com>
Sat, 25 Jun 2011 03:08:33 +0000 (22:08 -0500)
pdf.js
security.js

diff --git a/pdf.js b/pdf.js
index 3ebedd9e18787d73df10ab11e55dc5bb848d8305..a4de3d8b2a79b9635a3874e3b5f8c0879ae24bdf 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -716,7 +716,7 @@ var PredictorStream = (function() {
         var rawBytes = this.stream.getBytes(rowBytes);
 
         var bufferLength = this.bufferLength;
-        var buffer = this.ensureBuffer(bufferLength + pixBytes);
+        var buffer = this.ensureBuffer(bufferLength + rowBytes);
 
         var currentRow = buffer.subarray(bufferLength, bufferLength + rowBytes);
         var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
@@ -833,7 +833,7 @@ var DecryptStream = (function() {
       var buffer = this.ensureBuffer(bufferLength + n);
       for (i = 0; i < n; i++)
         buffer[bufferLength++] = chunk[i];
-      this.bufferLength = n;
+      this.bufferLength = bufferLength;
       this.eof = n < chunkSize;
     };
 
@@ -1468,7 +1468,7 @@ var Parser = (function() {
 
             stream = stream.makeSubStream(pos, length, dict);
             if (cipherTransform)
-                stream = cipherTransform.createString(stream);
+                stream = cipherTransform.createStream(stream);
             stream = this.filter(stream, dict, length);
             stream.parameters = dict;
             return stream;
@@ -1802,7 +1802,11 @@ var XRef = (function() {
                     }
                     error("bad XRef entry");
                 }
-                e = parser.getObj(this.encrypt);
+                if (this.encrypt) {
+                    e = parser.getObj(this.encrypt.createCipherTransform(num, gen));
+                } else {
+                    e = parser.getObj();
+                }
                 // Don't cache streams since they are mutable.
                 if (!IsStream(e))
                     this.cache[num] = e;
@@ -2629,7 +2633,7 @@ var CanvasGraphics = (function() {
                             }
                         }
                     } else if (cmd == "Tf") { // eagerly collect all fonts
-                        var fontRes; // = resources.get("Font");
+                        var fontRes = resources.get("Font");
                         if (fontRes) {
                             fontRes = xref.fetchIfRef(fontRes);
                             var font = xref.fetchIfRef(fontRes.get(args[0].name));
index d6aa8d3b29fc910b0a550cfae2b84ebbddfed61c..14cc21902a153ce279e6eea8dcafee27fdb234c6 100644 (file)
@@ -5,7 +5,6 @@
 
 var ARCFourCipher = (function() {
   function constructor(key) {
-    var key = this.key;
     this.a = 0;
     this.b = 0;
     var s = new Uint8Array(256);
@@ -133,13 +132,13 @@ var CipherTransform = (function() {
   }
   constructor.prototype = {
     createStream: function (stream) {
-      var cipher = new streamCipherConstructor();
+      var cipher = new this.streamCipherConstructor();
       return new DecryptStream(stream, function(data) {
         return cipher.encryptBlock(data);
       });
     },
     decryptString: function(s) {
-      var cipher = new stringCipherConstructor();
+      var cipher = new this.stringCipherConstructor();
       var data = string2bytes(s);
       data = cipher.encryptBlock(data);
       return bytes2string(data);
@@ -240,9 +239,9 @@ var CipherTransformFactory = (function() {
   constructor.prototype = {
     createCipherTransform: function(num, gen) {
       var encryptionKey = this.encryptionKey;
-      var key = new Uint8Array(encryptionKey.length + 5), i, j, n;
-      for (j = 0, n = encryptionKey.length; j < n; ++j)
-        key[j] = encryptionKey[j];
+      var key = new Uint8Array(encryptionKey.length + 5), i, n;
+      for (i = 0, n = encryptionKey.length; i < n; ++i)
+        key[i] = encryptionKey[i];
       key[i++] = num & 0xFF;
       key[i++] = (num >> 8) & 0xFF;
       key[i++] = (num >> 16) & 0xFF;