mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #9838 from Snuffleupagus/invalid-path-OPS
Error, rather than warn, once a number of invalid path operators are encountered in `EvaluatorPreprocessor.read` (bug 1443140)
This commit is contained in:
commit
6fa2c779b5
4 changed files with 57 additions and 7 deletions
|
@ -2932,6 +2932,8 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
|
|||
t['null'] = null;
|
||||
});
|
||||
|
||||
const MAX_INVALID_PATH_OPS = 20;
|
||||
|
||||
function EvaluatorPreprocessor(stream, xref, stateManager) {
|
||||
this.opMap = getOPMap();
|
||||
// TODO(mduan): pass array of knownCommands rather than this.opMap
|
||||
|
@ -2939,6 +2941,7 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
|
|||
this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
|
||||
this.stateManager = stateManager;
|
||||
this.nonProcessedArgs = [];
|
||||
this._numInvalidPathOPS = 0;
|
||||
}
|
||||
|
||||
EvaluatorPreprocessor.prototype = {
|
||||
|
@ -2976,7 +2979,7 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
|
|||
// Check that the command is valid
|
||||
var opSpec = this.opMap[cmd];
|
||||
if (!opSpec) {
|
||||
warn('Unknown command "' + cmd + '"');
|
||||
warn(`Unknown command "${cmd}".`);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -3002,18 +3005,28 @@ var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
|
|||
}
|
||||
|
||||
if (argsLength < numArgs) {
|
||||
const partialMsg = `command ${cmd}: expected ${numArgs} args, ` +
|
||||
`but received ${argsLength} args.`;
|
||||
|
||||
// Incomplete path operators, in particular, can result in fairly
|
||||
// chaotic rendering artifacts. Hence the following heuristics is
|
||||
// used to error, rather than just warn, once a number of invalid
|
||||
// path operators have been encountered (fixes bug1443140.pdf).
|
||||
if ((fn >= OPS.moveTo && fn <= OPS.endPath) && // Path operator
|
||||
++this._numInvalidPathOPS > MAX_INVALID_PATH_OPS) {
|
||||
throw new FormatError(`Invalid ${partialMsg}`);
|
||||
}
|
||||
// If we receive too few arguments, it's not possible to execute
|
||||
// the command, hence we skip the command.
|
||||
warn('Skipping command ' + fn + ': expected ' + numArgs +
|
||||
' args, but received ' + argsLength + ' args.');
|
||||
warn(`Skipping ${partialMsg}`);
|
||||
if (args !== null) {
|
||||
args.length = 0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
} else if (argsLength > numArgs) {
|
||||
info('Command ' + fn + ': expected [0,' + numArgs +
|
||||
'] args, but received ' + argsLength + ' args.');
|
||||
info(`Command ${cmd}: expected [0, ${numArgs}] args, ` +
|
||||
`but received ${argsLength} args.`);
|
||||
}
|
||||
|
||||
// TODO figure out how to type-check vararg functions
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue