diff --git a/base/core/parser.js b/base/core/parser.js index 06f3e3e..87d6f1b 100755 --- a/base/core/parser.js +++ b/base/core/parser.js @@ -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]; @@ -253,7 +254,7 @@ var Parser = (function ParserClosure() { stream.pos += scanLength; } if (!found) { - error('Missing endstream'); + error('Missing endstream or invalid stream'); } length = skipped; diff --git a/base/display/canvas.js b/base/display/canvas.js index fc87c14..43b2e42 100755 --- a/base/display/canvas.js +++ b/base/display/canvas.js @@ -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') : @@ -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(); diff --git a/package.json b/package.json index 60cf682..c4a4b38 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/test/pdf/misc/i306_err_invalid.pdf b/test/pdf/misc/i306_err_invalid.pdf new file mode 100644 index 0000000..a79c66e Binary files /dev/null and b/test/pdf/misc/i306_err_invalid.pdf differ