1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 09:38:06 +02:00

Let Lexer.getNumber treat more invalid "numbers" as zero (issue 15604)

In the referenced PDF document there are "numbers" which consist only of `-.`, and while that's obviously not valid Adobe Reader seems to handle it just fine.
Letting this method ignore more invalid "numbers" was suggested during the review of PR 14543, so let's simply relax our the validation here.
This commit is contained in:
Jonas Jenwald 2022-10-20 19:40:25 +02:00
parent 7dc16c237a
commit 71bd8b4de9
4 changed files with 24 additions and 22 deletions

View file

@ -897,21 +897,15 @@ class Lexer {
ch = this.nextChar();
}
if (ch < /* '0' = */ 0x30 || ch > /* '9' = */ 0x39) {
const msg = `Invalid number: ${String.fromCharCode(ch)} (charCode ${ch})`;
if (isWhiteSpace(ch) || ch === /* EOF = */ -1) {
// This is consistent with Adobe Reader (fixes issue9252.pdf).
if (divideBy === 10 && sign === 0) {
warn("Lexer.getNumber - treating a single decimal point as zero.");
return 0;
}
// This is consistent with Adobe Reader (fixes bug1753983.pdf).
if (divideBy === 0 && sign === -1) {
warn("Lexer.getNumber - treating a single minus sign as zero.");
return 0;
}
// This is consistent with Adobe Reader (fixes issue9252.pdf,
// issue15604.pdf, bug1753983.pdf).
info(`Lexer.getNumber - "${msg}".`);
return 0;
}
throw new FormatError(
`Invalid number: ${String.fromCharCode(ch)} (charCode ${ch})`
);
throw new FormatError(msg);
}
sign = sign || 1;