1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Let Lexer.getObj return a dummy-Cmd for commands that start with a non-visible ASCII character (issue 13999)

This way we avoid breaking badly generated PDF documents where a non-visible ASCII character is "glued" to a valid command.
This commit is contained in:
Jonas Jenwald 2021-09-11 18:29:31 +02:00
parent 99e442941c
commit a47844d1fc
4 changed files with 46 additions and 2 deletions

View file

@ -1255,7 +1255,7 @@ class Lexer {
return Cmd.get("}");
case 0x29: // ')'
// Consume the current character in order to avoid permanently hanging
// the worker thread if `Lexer.getObject` is called from within a loop
// the worker thread if `Lexer.getObj` is called from within a loop
// containing try-catch statements, since we would otherwise attempt
// to parse the *same* character over and over (fixes issue8061.pdf).
this.nextChar();
@ -1264,6 +1264,15 @@ class Lexer {
// Start reading a command.
let str = String.fromCharCode(ch);
// A valid command cannot start with a non-visible ASCII character,
// and the next character may be (the start of) a valid command.
if (ch < 0x20 || ch > 0x7f) {
const nextCh = this.peekChar();
if (nextCh >= 0x20 && nextCh <= 0x7f) {
this.nextChar();
return Cmd.get(str);
}
}
const knownCommands = this.knownCommands;
let knownCommandFound = knownCommands && knownCommands[str] !== undefined;
while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {