From 267f312f135a29c809cdee905624e19700cd927c Mon Sep 17 00:00:00 2001 From: Andreas Gal Date: Fri, 3 Jun 2011 14:16:04 -0700 Subject: [PATCH] fix length/end of stream handling --- pdf.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pdf.js b/pdf.js index ecb2143..f3145f1 100644 --- a/pdf.js +++ b/pdf.js @@ -51,20 +51,23 @@ var Stream = (function() { this.bytes = new Uint8Array(arrayBuffer); this.start = start || 0; this.pos = this.start; - this.length = (start + length) || arrayBuffer.byteLength; + this.end = (start + length) || arrayBuffer.byteLength; this.dict = dict; } constructor.prototype = { + get length() { + return this.end - this.start; + }, getByte: function() { var bytes = this.bytes; - if (this.pos >= this.length) + if (this.pos >= this.end) return -1; return bytes[this.pos++]; }, lookChar: function() { var bytes = this.bytes; - if (this.pos >= this.length) + if (this.pos >= this.end) return; return String.fromCharCode(bytes[this.pos]); }, @@ -1913,11 +1916,11 @@ var PDFDoc = (function() { } function find(stream, needle, limit, backwards) { - var length = stream.length; var pos = stream.pos; + var end = stream.end; var str = ""; - if (pos + limit > length) - limit = length - pos; + if (pos + limit > end) + limit = end - pos; for (var n = 0; n < limit; ++n) str += stream.getChar(); stream.pos = pos; @@ -1951,7 +1954,7 @@ var PDFDoc = (function() { startXRef = stream.pos + 6; } else { // Find startxref at the end of the file. - var start = stream.length - 1024; + var start = stream.end - 1024; if (start < 0) start = 0; stream.pos = start; -- 2.39.5