Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent errors in sanitizeTTProgram, during parsing of CALL functions, when encountering invalid functions stack deltas (bug 1473809) #9886

Merged
merged 1 commit into from
Jul 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
!bug1108301.pdf
!bug1157493.pdf
!bug1250079.pdf
!bug1473809.pdf
!pdfjsbad1586.pdf
!freeculture.pdf
!issue6006.pdf
Expand Down
Binary file added test/pdfs/bug1473809.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down