]> git.parisson.com Git - pdf.js.git/commitdiff
Better 'EI' matching (ref #536)
authornotmasteryet <async.processingjs@yahoo.com>
Tue, 27 Sep 2011 02:17:16 +0000 (21:17 -0500)
committernotmasteryet <async.processingjs@yahoo.com>
Tue, 27 Sep 2011 02:17:16 +0000 (21:17 -0500)
pdf.js

diff --git a/pdf.js b/pdf.js
index 449fd9c16f858e29b69517d51efadb10c4eb8aa0..ba05dd1ff1388b9926d2c7a8029682c9b158697f 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -2832,14 +2832,37 @@ var Parser = (function parserParser() {
       // parse image stream
       var startPos = stream.pos;
 
-      var c1 = stream.getChar();
-      var c2 = stream.getChar();
-      while (!(c1 == 'E' && c2 == 'I') && c2 != null) {
-        c1 = c2;
-        c2 = stream.getChar();
+      // searching for the /\sEI\s/
+      var state = 0, ch;
+      while (state != 4 && (ch = stream.getByte()) != null) {
+        switch (ch) {
+          case 0x20:
+          case 0x0D:
+          case 0x0A:
+            state = state === 3 ? 4 : 1;
+            break;
+          case 0x45:
+            state = state === 1 ? 2 : 0;
+            break;
+          case 0x49:
+            state = state === 2 ? 3 : 0;
+            break;
+          default:
+            state = 0;
+            break;
+        }
+      }
+
+      // TODO improve the small images performance to remove the limit
+      var inlineImgLimit = 500;
+      if (++this.inlineImg >= inlineImgLimit) {
+        if (this.inlineImg === inlineImgLimit)
+          warn('Too many inline images');
+        this.shift();
+        return null;
       }
 
-      var length = (stream.pos - 2) - startPos;
+      var length = (stream.pos - 4) - startPos;
       var imageStream = stream.makeSubStream(startPos, length, dict);
       if (cipherTransform)
         imageStream = cipherTransform.createStream(imageStream);
@@ -4377,7 +4400,7 @@ var PartialEvaluator = (function partialEvaluator() {
           fnArray.push(fn);
           argsArray.push(args);
           args = [];
-        } else {
+        } else if (obj != null) {
           assertWellFormed(args.length <= 33, 'Too many arguments');
           args.push(obj);
         }