From 43847d7ff8da1876975edf741f889342a816e216 Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Sat, 7 Dec 2013 23:19:50 +0100 Subject: [PATCH 1/2] Set eof to true at the end of a FlateStream At the initialization of `Lexer_getObj` (in `parser.js`), there's a loop that skips whitespace and breaks out whenever EOF is encountered. (https://github.com/mozilla/pdf.js/blob/88ec2bd1a/src/core/parser.js#L586-L599) Whenever the current character is not a whitespace character, `ch = this.nextChar();` is used to find the next character (using `return this.currentChar = this.stream.getByte())`). The aforementioned `getByte` method retrieves the next byte using (https://github.com/mozilla/pdf.js/blob/88ec2bd1a/src/core/stream.js#L122-L128) var pos = this.pos; while (this.bufferLength <= pos) { if (this.eof) return -1; this.readBlock(); } return this.buffer[this.pos++]; This piece of code relies on this.eof to detect whether the last character has been read. When the stream is a `FlateStream`, and the end of the stream has been reached, then **`this.eof` is not set to `true`**, because this check is done inside a loop that does not occur when the read block size is zero: (https://github.com/mozilla/pdf.js/blob/88ec2bd1ac/src/core/stream.js#L511-L517) for (var n = bufferLength; n < end; ++n) { if (typeof (b = bytes[bytesPos++]) == 'undefined') { this.eof = true; break; } buffer[n] = b; } This commit fixes the issue by setting this.eof to true whenever the loop is not going to run (i.e. when bufferLength === end, i.e. blockLen === 0). --- src/core/stream.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/core/stream.js b/src/core/stream.js index 61f1af544..6e25b36c2 100644 --- a/src/core/stream.js +++ b/src/core/stream.js @@ -508,12 +508,18 @@ var FlateStream = (function FlateStreamClosure() { var buffer = this.ensureBuffer(bufferLength + blockLen); var end = bufferLength + blockLen; this.bufferLength = end; - for (var n = bufferLength; n < end; ++n) { - if (typeof (b = bytes[bytesPos++]) == 'undefined') { + if (blockLen === 0) { + if (typeof bytes[bytesPos] == 'undefined') { this.eof = true; - break; } - buffer[n] = b; + } else { + for (var n = bufferLength; n < end; ++n) { + if (typeof (b = bytes[bytesPos++]) == 'undefined') { + this.eof = true; + break; + } + buffer[n] = b; + } } this.bytesPos = bytesPos; return; From 4ff1d45f162bc78992d7912fdf10cc27f9de10d3 Mon Sep 17 00:00:00 2001 From: Rob Wu Date: Tue, 17 Dec 2013 21:32:24 +0100 Subject: [PATCH 2/2] Add pdf from issue 3885 to tests Source: https://www.dropbox.com/s/ooqk82fq0gr5p6f/test-min-notext-opt.pdf --- test/pdfs/.gitignore | 1 + test/pdfs/issue3885.pdf | Bin 0 -> 6988 bytes test/test_manifest.json | 8 ++++++++ 3 files changed, 9 insertions(+) create mode 100644 test/pdfs/issue3885.pdf diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 76685349d..24268df1d 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -62,3 +62,4 @@ !issue3371.pdf !issue2956.pdf !bug946506.pdf +!issue3885.pdf diff --git a/test/pdfs/issue3885.pdf b/test/pdfs/issue3885.pdf new file mode 100644 index 0000000000000000000000000000000000000000..183294ccff0d0fdd8efc2a7a165acd7e15a86b24 GIT binary patch literal 6988 zcmeHMU5p!76?T&}O0BpmkQ5{+y>S$ppxXCm=FX41yUng0XSai8tH}?i6eU+y6)m$ zy7A;kHh$x_lmB|d{`Sqc&TRYTg-73{8{d$WF#=tMOXuJSZsD4jAoZ; z8Ww~fk|xVIJ1xfGl4W=`yP1Opcjq#UP>FD+Qb|@B|0E%|5V8m7k&Fw$T}p|>2!Z=4 zqQKo-_TYns-Bqn@$aT{v(RSKSuyuS_+o%-n z8o<0HOIn)g5>sVBTu(Cwlx2u>Elm|w;#yQ1)s@w>s;E?>1G=G9B5ImwM3*F3R82E3 z)4(i5k-=hpVN_G%X;oJ#klo)wpc+co=rTUKAxM!KpRipnAjSa`0ySSpl9HxWqWUt<+ipY9PdpmBsSL%aV0dn=;}Z!;B#6`_ zRF_myqVMZ?`xgX{frj&-=O-iZu;|+6g5@n?crYzT(xGrTe@HBfsGq8SBJ>;+@~%%o z`h@jF*j{PHaesQwj*lo0zR~yM{C?MNJK(|sF1bd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test_manifest.json b/test/test_manifest.json index 5a14c69ad..1b545a368 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -61,6 +61,14 @@ "lastPage": 2, "type": "eq" }, + { "id": "issue3885", + "file": "pdfs/issue3885.pdf", + "md5": "319c998910453bc44d40c7748cd2cb79", + "rounds": 1, + "firstPage": 1, + "lastPage": 1, + "type": "eq" + }, { "id": "issue2833", "file": "pdfs/issue2833.pdf", "md5": "7bc6e17c41586155c188d7408bcb9ab5",