Revert commit fc73e2e (PR 5005) for breaking certain PDF files

This commit is contained in:
Jonas Jenwald 2014-07-22 21:17:57 +02:00
parent 780f86b9c3
commit b950118681
2 changed files with 13 additions and 7 deletions

View File

@ -14,8 +14,8 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
/* globals assert, bytesToString, calculateMD5, Catalog, Dict, error, info, /* globals assert, calculateMD5, Catalog, Dict, error, info, isArray,
isArray, isArrayBuffer, isName, isStream, isString, isArrayBuffer, isName, isStream, isString, createPromiseCapability,
Linearization, NullStream, PartialEvaluator, shadow, Stream, Lexer, Linearization, NullStream, PartialEvaluator, shadow, Stream, Lexer,
StreamsSequenceStream, stringToPDFString, stringToBytes, Util, XRef, StreamsSequenceStream, stringToPDFString, stringToBytes, Util, XRef,
MissingDataException, Promise, Annotation, ObjectLoader, OperatorList MissingDataException, Promise, Annotation, ObjectLoader, OperatorList
@ -301,10 +301,14 @@ var PDFDocument = (function PDFDocumentClosure() {
function find(stream, needle, limit, backwards) { function find(stream, needle, limit, backwards) {
var pos = stream.pos; var pos = stream.pos;
var end = stream.end; var end = stream.end;
var strBuf = [];
if (pos + limit > end) { if (pos + limit > end) {
limit = end - pos; limit = end - pos;
} }
var str = bytesToString(stream.getBytes(limit)); for (var n = 0; n < limit; ++n) {
strBuf.push(String.fromCharCode(stream.getByte()));
}
var str = strBuf.join('');
stream.pos = pos; stream.pos = pos;
var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle); var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
if (index == -1) { if (index == -1) {

View File

@ -531,10 +531,12 @@ var FlateStream = (function FlateStreamClosure() {
this.eof = true; this.eof = true;
} }
} else { } else {
var block = str.getBytes(blockLen); for (var n = bufferLength; n < end; ++n) {
buffer.set(block, bufferLength); if ((b = str.getByte()) === -1) {
if (block.length < blockLen) { this.eof = true;
this.eof = true; break;
}
buffer[n] = b;
} }
} }
return; return;