diff options
author | Albert Astals Cid <aacid@kde.org> | 2017-04-05 23:18:52 +0200 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2017-04-05 23:20:27 +0200 |
commit | cc7809e73c71e0e6b7db29dc8a12cfb573448b77 (patch) | |
tree | 2262d725ef34292cfb1a1c448400eeb86df79b22 | |
parent | 2bbd110113f789c56609b3288258f667e0f3851a (diff) |
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
-rw-r--r-- | poppler/XRef.cc | 30 |
1 files changed, 19 insertions, 11 deletions
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 |