[Pkg-javascript-commits] [pdf.js] 30/207: Optimization for FlateStream_getCode, making more pdfs parsable.

David Prévot taffit at moszumanska.debian.org
Mon Jul 28 15:36:26 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 22a0e7fe65583b73c956080e03067403d4f3a83f
Author: Fabian Lange <lange.fabian at gmail.com>
Date:   Thu Jun 5 16:49:29 2014 +0200

    Optimization for FlateStream_getCode, making more pdfs parsable.
    
    This commit cleans up the FlateStream_getCode method, and removes a few error
    conditions.
    Previously it would fail if the codeSize is less than maxLen if end of stream
    is reached. However in the document linked below there is a sub-stream
    (the one starting at pos 337) which has maxLen set to 11, but actually
    contains only 10. After breaking the sanity check still applies, and in this
    case passes validating codeSize(10)==codeLen(10).
    
     http://www.cafeculture.com/wp-content/uploads/2014/03/V-CM-BR-086-04002-1346-0258-GP-Brazil-Fazenda-Cafe-Cambara-Terra-Preta-Microlot-Sample-0460-13-Pulped-Natural-60Kg.pdf
---
 src/core/stream.js | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/core/stream.js b/src/core/stream.js
index 669cab1..8688434 100644
--- a/src/core/stream.js
+++ b/src/core/stream.js
@@ -430,10 +430,12 @@ var FlateStream = (function FlateStreamClosure() {
     var codeSize = this.codeSize;
     var codeBuf = this.codeBuf;
 
+    var b;
     while (codeSize < maxLen) {
-      var b;
       if ((b = str.getByte()) === -1) {
-        error('Bad encoding in flate stream');
+        // premature end of stream. code might however still be valid.
+        // codeSize < codeLen check below guards against incomplete codeVal.
+        break;
       }
       codeBuf |= (b << codeSize);
       codeSize += 8;
@@ -441,7 +443,7 @@ var FlateStream = (function FlateStreamClosure() {
     var code = codes[codeBuf & ((1 << maxLen) - 1)];
     var codeLen = code >> 16;
     var codeVal = code & 0xffff;
-    if (codeSize === 0 || codeSize < codeLen || codeLen === 0) {
+    if (codeLen < 1 || codeSize < codeLen) {
       error('Bad encoding in flate stream');
     }
     this.codeBuf = (codeBuf >> codeLen);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list