Browse Source

Prevent failures in the "scanning for endstream" code, in `Parser_makeStream`, by handling the case where 'endstream' is split between contiguous chunks (issue 1536)

Jonas Jenwald 9 years ago
parent
commit
15ce96a6eb
  1. 25
      src/core/parser.js
  2. 1
      test/pdfs/issue1536.pdf.link
  3. 1
      test/pdfs/issue2098.pdf.link
  4. 18
      test/test_manifest.json

25
src/core/parser.js

@ -488,23 +488,22 @@ var Parser = (function ParserClosure() {
break; break;
} }
found = false; found = false;
for (i = 0, j = 0; i < scanLength; i++) { i = 0;
var b = scanBytes[i]; while (i < scanLength) {
if (b !== ENDSTREAM_SIGNATURE[j]) { j = 0;
i -= j; while (j < ENDSTREAM_SIGNATURE_LENGTH &&
j = 0; scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
} else {
j++; j++;
if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
i++;
found = true;
break;
}
} }
if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
found = true;
break;
}
i++;
} }
if (found) { if (found) {
skipped += i - ENDSTREAM_SIGNATURE_LENGTH; skipped += i;
stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH; stream.pos += i;
break; break;
} }
skipped += scanLength; skipped += scanLength;

1
test/pdfs/issue1536.pdf.link

@ -0,0 +1 @@
http://web.archive.org/web/20150922201828/http://w2.eff.org/legal/cases/betamax/betamax_oral_argument2.pdf

1
test/pdfs/issue2098.pdf.link

@ -0,0 +1 @@
http://web.archive.org/web/20160125220711/http://www.star.bnl.gov/public/daq/HARDWARE/21264_data_sheet.pdf

18
test/test_manifest.json

@ -921,6 +921,24 @@
"rounds": 1, "rounds": 1,
"type": "eq" "type": "eq"
}, },
{ "id": "issue1536",
"file": "pdfs/issue1536.pdf",
"md5": "bcaa52e6216399592ad5aa9fc49f1436",
"rounds": 1,
"link": true,
"firstPage": 6,
"lastPage": 6,
"type": "eq"
},
{ "id": "issue2098",
"file": "pdfs/issue2098.pdf",
"md5": "e9fa2b7cb935ffb95b510322d1e047e1",
"rounds": 1,
"link": true,
"firstPage": 1,
"lastPage": 1,
"type": "eq"
},
{ "id": "bpl13210", { "id": "bpl13210",
"file": "pdfs/bpl13210.pdf", "file": "pdfs/bpl13210.pdf",
"md5": "8a08512baa9fa95378d9ad4b995947c7", "md5": "8a08512baa9fa95378d9ad4b995947c7",

Loading…
Cancel
Save