Skip to content

Commit 15ce96a

Browse files
committed
Prevent failures in the "scanning for endstream" code, in Parser_makeStream, by handling the case where 'endstream' is split between contiguous chunks (issue 1536)
1 parent 051a074 commit 15ce96a

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

src/core/parser.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -488,23 +488,22 @@ var Parser = (function ParserClosure() {
488488
break;
489489
}
490490
found = false;
491-
for (i = 0, j = 0; i < scanLength; i++) {
492-
var b = scanBytes[i];
493-
if (b !== ENDSTREAM_SIGNATURE[j]) {
494-
i -= j;
495-
j = 0;
496-
} else {
491+
i = 0;
492+
while (i < scanLength) {
493+
j = 0;
494+
while (j < ENDSTREAM_SIGNATURE_LENGTH &&
495+
scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
497496
j++;
498-
if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
499-
i++;
500-
found = true;
501-
break;
502-
}
503497
}
498+
if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
499+
found = true;
500+
break;
501+
}
502+
i++;
504503
}
505504
if (found) {
506-
skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
507-
stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
505+
skipped += i;
506+
stream.pos += i;
508507
break;
509508
}
510509
skipped += scanLength;

test/pdfs/issue1536.pdf.link

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://web.archive.org/web/20150922201828/http://w2.eff.org/legal/cases/betamax/betamax_oral_argument2.pdf

test/pdfs/issue2098.pdf.link

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
http://web.archive.org/web/20160125220711/http://www.star.bnl.gov/public/daq/HARDWARE/21264_data_sheet.pdf

test/test_manifest.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,24 @@
921921
"rounds": 1,
922922
"type": "eq"
923923
},
924+
{ "id": "issue1536",
925+
"file": "pdfs/issue1536.pdf",
926+
"md5": "bcaa52e6216399592ad5aa9fc49f1436",
927+
"rounds": 1,
928+
"link": true,
929+
"firstPage": 6,
930+
"lastPage": 6,
931+
"type": "eq"
932+
},
933+
{ "id": "issue2098",
934+
"file": "pdfs/issue2098.pdf",
935+
"md5": "e9fa2b7cb935ffb95b510322d1e047e1",
936+
"rounds": 1,
937+
"link": true,
938+
"firstPage": 1,
939+
"lastPage": 1,
940+
"type": "eq"
941+
},
924942
{ "id": "bpl13210",
925943
"file": "pdfs/bpl13210.pdf",
926944
"md5": "8a08512baa9fa95378d9ad4b995947c7",

0 commit comments

Comments
 (0)