Skip to content

Commit

Permalink
fix: break infinite loop from invalid stream, add i306_err_invalid.pd…
Browse files Browse the repository at this point in the history
…f to verify fix of #306
  • Loading branch information
modesty committed Dec 30, 2024
1 parent 7721899 commit a9640cb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion base/core/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ var Parser = (function ParserClosure() {
while (stream.pos < stream.end) {
var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
if (scanLength <= 0) break; // no match possible, end of stream or invalid stream
var found = false, i, ii, j;
for (i = 0, j = 0; i < scanLength; i++) {
var b = scanBytes[i];
Expand All @@ -253,7 +254,7 @@ var Parser = (function ParserClosure() {
stream.pos += scanLength;
}
if (!found) {
error('Missing endstream');
error('Missing endstream or invalid stream');
}
length = skipped;

Expand Down
8 changes: 5 additions & 3 deletions base/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
this.current.font = fontObj;
this.current.fontSize = size;

if (fontObj.coded)
return; // we don't need ctx.font for Type3 fonts
if (fontObj.coded) {
warn('Unsupported Type3 font (custom Glyph) - ' + fontRefName);
return; // we don't need ctx.font for Type3 fonts
}

var name = fontObj.loadedName || 'sans-serif';
var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
Expand Down Expand Up @@ -1627,7 +1629,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
//MQZ. make sure endGroup is always invoked after beginGroup
if (this.groupLevel == 0)
this.beginGroup(group);

this.groupLevel--;
var groupCtx = this.ctx;
this.ctx = this.groupStack.pop();
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"test:jest": "jest --config ./jest.config.json",
"test": "jest --config ./jest.config.json && npm run parse-r && npm run parse-fd",
"test:forms": "cd ./test && sh p2j.forms.sh",
"test:misc": "cd ./test && sh p2j.one.sh misc . \"Expected: 13 success, 5 fail exception with stack trace\" ",
"test:misc": "cd ./test && sh p2j.one.sh misc . \"Expected: 13 success, 6 exceptions with stack trace\" ",
"parse": "./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form",
"parse-s": "./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -s",
"parse-t": "./bin/pdf2json.js -f ./test/pdf/fd/form/F1040.pdf -o ./test/target/fd/form -s -t",
Expand All @@ -48,7 +48,7 @@
"parse-tb": "./bin/pdf2json.js -f ./test/pdf/misc/i242_testingWithTable.pdf -o ./test/target/misc",
"parse-tc": "./bin/pdf2json.js -f ./test/pdf/misc/i293_pdfpac.pdf -o ./test/target/misc",
"parse-rectFix": "./bin/pdf2json.js -f ./test/pdf/misc/pr298_rect_fix_from_upstream.pdf -o ./test/target/misc",
"parse-e": "./bin/pdf2json.js -f ./test/pdf/misc/i373_err_broken.pdf -o ./test/target/misc",
"parse-e": "./bin/pdf2json.js -f ./test/pdf/misc/i306_err_invalid.pdf -o ./test/target/misc",
"build:rollup": "rollup -c ./rollup.config.js",
"build:bundle-pdfjs-base": "node rollup/bundle-pdfjs-base.js",
"build": "npm run build:bundle-pdfjs-base && npm run build:rollup",
Expand Down
Binary file added test/pdf/misc/i306_err_invalid.pdf
Binary file not shown.

0 comments on commit a9640cb

Please sign in to comment.