Skip to content

Commit faa9020

Browse files
committed
Merge pull request #5069 from Snuffleupagus/revert-5005
Revert commit fc73e2e (PR 5005) for breaking certain PDF files
2 parents 780f86b + b950118 commit faa9020

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/core/core.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
/* globals assert, bytesToString, calculateMD5, Catalog, Dict, error, info,
18-
isArray, isArrayBuffer, isName, isStream, isString,
17+
/* globals assert, calculateMD5, Catalog, Dict, error, info, isArray,
18+
isArrayBuffer, isName, isStream, isString, createPromiseCapability,
1919
Linearization, NullStream, PartialEvaluator, shadow, Stream, Lexer,
2020
StreamsSequenceStream, stringToPDFString, stringToBytes, Util, XRef,
2121
MissingDataException, Promise, Annotation, ObjectLoader, OperatorList
@@ -301,10 +301,14 @@ var PDFDocument = (function PDFDocumentClosure() {
301301
function find(stream, needle, limit, backwards) {
302302
var pos = stream.pos;
303303
var end = stream.end;
304+
var strBuf = [];
304305
if (pos + limit > end) {
305306
limit = end - pos;
306307
}
307-
var str = bytesToString(stream.getBytes(limit));
308+
for (var n = 0; n < limit; ++n) {
309+
strBuf.push(String.fromCharCode(stream.getByte()));
310+
}
311+
var str = strBuf.join('');
308312
stream.pos = pos;
309313
var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
310314
if (index == -1) {

src/core/stream.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,10 +531,12 @@ var FlateStream = (function FlateStreamClosure() {
531531
this.eof = true;
532532
}
533533
} else {
534-
var block = str.getBytes(blockLen);
535-
buffer.set(block, bufferLength);
536-
if (block.length < blockLen) {
537-
this.eof = true;
534+
for (var n = bufferLength; n < end; ++n) {
535+
if ((b = str.getByte()) === -1) {
536+
this.eof = true;
537+
break;
538+
}
539+
buffer[n] = b;
538540
}
539541
}
540542
return;

0 commit comments

Comments
 (0)