[poppler] poppler/XRef.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Wed Apr 5 21:20:42 UTC 2017


 poppler/XRef.cc |   30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

New commits:
commit cc7809e73c71e0e6b7db29dc8a12cfb573448b77
Author: Albert Astals Cid <aacid at kde.org>
Date:   Wed Apr 5 23:18:52 2017 +0200

    Make XRef reconstruction a bit better
    
    Also detect streams whose endstream is on the middle of a line and not only at the beginning
    
    Bug #100509

diff --git a/poppler/XRef.cc b/poppler/XRef.cc
index 2add7dc0..8d8fac42 100644
--- a/poppler/XRef.cc
+++ b/poppler/XRef.cc
@@ -1023,17 +1023,25 @@ GBool XRef::constructXRef(GBool *wasReconstructed, GBool needCatalogDict) {
 	  }
         }
 
-      } else if (!strncmp(p, "endstream", 9)) {
-        if (streamEndsLen == streamEndsSize) {
-	  streamEndsSize += 64;
-          if (streamEndsSize >= INT_MAX / (int)sizeof(int)) {
-            error(errSyntaxError, -1, "Invalid 'endstream' parameter.");
-            return gFalse;
-          }
-	  streamEnds = (Goffset *)greallocn(streamEnds,
-					streamEndsSize, sizeof(Goffset));
-        }
-        streamEnds[streamEndsLen++] = pos;
+      } else {
+	char *endstream = strstr( p, "endstream" );
+	if (endstream) {
+	  int endstreamPos = endstream - p;
+	  if ((endstreamPos == 0 || Lexer::isSpace(p[endstreamPos-1] & 0xff)) // endstream is either at beginning or preceeded by space
+	    && (endstreamPos + 9 >= 256 || Lexer::isSpace(p[endstreamPos+9] & 0xff))) // endstream is either at end or followed by space
+	  {
+	    if (streamEndsLen == streamEndsSize) {
+	      streamEndsSize += 64;
+	      if (streamEndsSize >= INT_MAX / (int)sizeof(int)) {
+		error(errSyntaxError, -1, "Invalid 'endstream' parameter.");
+		return gFalse;
+	      }
+	      streamEnds = (Goffset *)greallocn(streamEnds,
+					    streamEndsSize, sizeof(Goffset));
+	    }
+	    streamEnds[streamEndsLen++] = pos + endstreamPos;
+	  }
+	}
       }
       if( token ) {
         p = token + 6;// strlen( "endobj" ) = 6


More information about the poppler mailing list