diff --git a/pdf.js b/pdf.js index 3ebedd9e1..a4de3d8b2 100644 --- 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)); diff --git a/security.js b/security.js index d6aa8d3b2..14cc21902 100644 --- a/security.js +++ b/security.js @@ -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;