diff --git a/src/core/fonts.js b/src/core/fonts.js index f6fdd893d9795..1684446937921 100644 --- a/src/core/fonts.js +++ b/src/core/fonts.js @@ -2109,21 +2109,32 @@ var Font = (function FontClosure() { if (!inFDEF && !inELSE) { // collecting information about which functions are used funcId = stack[stack.length - 1]; - ttContext.functionsUsed[funcId] = true; - if (funcId in ttContext.functionsStackDeltas) { - stack.length += ttContext.functionsStackDeltas[funcId]; - } else if (funcId in ttContext.functionsDefined && - !functionsCalled.includes(funcId)) { - callstack.push({ data, i, stackTop: stack.length - 1, }); - functionsCalled.push(funcId); - pc = ttContext.functionsDefined[funcId]; - if (!pc) { - warn('TT: CALL non-existent function'); - ttContext.hintsValid = false; - return; + if (isNaN(funcId)) { + info('TT: CALL empty stack (or invalid entry).'); + } else { + ttContext.functionsUsed[funcId] = true; + if (funcId in ttContext.functionsStackDeltas) { + let newStackLength = stack.length + + ttContext.functionsStackDeltas[funcId]; + if (newStackLength < 0) { + warn('TT: CALL invalid functions stack delta.'); + ttContext.hintsValid = false; + return; + } + stack.length = newStackLength; + } else if (funcId in ttContext.functionsDefined && + !functionsCalled.includes(funcId)) { + callstack.push({ data, i, stackTop: stack.length - 1, }); + functionsCalled.push(funcId); + pc = ttContext.functionsDefined[funcId]; + if (!pc) { + warn('TT: CALL non-existent function'); + ttContext.hintsValid = false; + return; + } + data = pc.data; + i = pc.i; } - data = pc.data; - i = pc.i; } } } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 1d643cb1d97f7..bd38ac1667d8e 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -151,6 +151,7 @@ !bug1108301.pdf !bug1157493.pdf !bug1250079.pdf +!bug1473809.pdf !pdfjsbad1586.pdf !freeculture.pdf !issue6006.pdf diff --git a/test/pdfs/bug1473809.pdf b/test/pdfs/bug1473809.pdf new file mode 100644 index 0000000000000..ed388df178531 Binary files /dev/null and b/test/pdfs/bug1473809.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index b69054237f909..defb40f4f055b 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -143,6 +143,13 @@ "lastPage": 4, "type": "eq" }, + { "id": "bug1473809", + "file": "pdfs/bug1473809.pdf", + "md5": "4b1ca51cf8cad58a1ce0618667341c76", + "rounds": 1, + "link": false, + "type": "eq" + }, { "id": "issue2531", "file": "pdfs/issue2531.pdf", "md5": "c58e6642d8a6e2ddd5e07a543ef8f30d",