diff --git a/src/parser.js b/src/parser.js index a0f6c295e..ef6d512b5 100644 --- a/src/parser.js +++ b/src/parser.js @@ -154,13 +154,22 @@ var Parser = (function ParserClosure() { var startPos = stream.pos; // searching for the /EI\s/ - var state = 0, ch; + var state = 0, ch, i, ii; while (state != 4 && (ch = stream.getByte()) !== null && ch !== undefined) { switch (ch) { case 0x20: case 0x0D: case 0x0A: + // let's check next five bytes to be ASCII... just be sure + var followingBytes = stream.peekBytes(5); + for (i = 0, ii = followingBytes.length; i < ii; i++) { + ch = followingBytes[i]; + if (ch !== 0x0A && ch != 0x0D && (ch < 0x20 || ch > 0x7F)) { + state = 0; + break; // some binary stuff found, resetting the state + } + } state = state === 3 ? 4 : 0; break; case 0x45: diff --git a/src/stream.js b/src/stream.js index 6320c6fc0..b01075840 100644 --- a/src/stream.js +++ b/src/stream.js @@ -57,6 +57,11 @@ var Stream = (function StreamClosure() { this.pos = end; return bytes.subarray(pos, end); }, + peekBytes: function Stream_peekBytes(length) { + var bytes = this.getBytes(length); + this.pos -= bytes.length; + return bytes; + }, lookChar: function Stream_lookChar() { if (this.pos >= this.end) return null; @@ -161,6 +166,11 @@ var DecodeStream = (function DecodeStreamClosure() { this.pos = end; return this.buffer.subarray(pos, end); }, + peekBytes: function DecodeStream_peekBytes(length) { + var bytes = this.getBytes(length); + this.pos -= bytes.length; + return bytes; + }, lookChar: function DecodeStream_lookChar() { var pos = this.pos; while (this.bufferLength <= pos) { diff --git a/test/pdfs/bug878194.pdf.link b/test/pdfs/bug878194.pdf.link new file mode 100644 index 000000000..10344f735 --- /dev/null +++ b/test/pdfs/bug878194.pdf.link @@ -0,0 +1 @@ +https://bugzilla.mozilla.org/attachment.cgi?id=756735 diff --git a/test/test_manifest.json b/test/test_manifest.json index 53730a45f..3f1f6449a 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -1104,6 +1104,15 @@ "type": "eq", "about": "True type font with encoding dict with no base encoding but with differences." }, + { "id": "bug878194", + "file": "pdfs/bug878194.pdf", + "md5": "c616b21fd2a1a65acc2de0f41e59a8b5", + "link": "true", + "rounds": 1, + "firstPage": 4, + "lastPage": 4, + "type": "load" + }, { "id": "p020121130574743273239", "file": "pdfs/P020121130574743273239.pdf", "md5": "271b65885d42d174cbc597ca89becb1a",