Merge pull request #15606 from Snuffleupagus/issue-15604
Let `Lexer.getNumber` treat more invalid "numbers" as zero (issue 15604)
This commit is contained in:
commit
f5711fc385
@ -897,21 +897,15 @@ class Lexer {
|
|||||||
ch = this.nextChar();
|
ch = this.nextChar();
|
||||||
}
|
}
|
||||||
if (ch < /* '0' = */ 0x30 || ch > /* '9' = */ 0x39) {
|
if (ch < /* '0' = */ 0x30 || ch > /* '9' = */ 0x39) {
|
||||||
|
const msg = `Invalid number: ${String.fromCharCode(ch)} (charCode ${ch})`;
|
||||||
|
|
||||||
if (isWhiteSpace(ch) || ch === /* EOF = */ -1) {
|
if (isWhiteSpace(ch) || ch === /* EOF = */ -1) {
|
||||||
// This is consistent with Adobe Reader (fixes issue9252.pdf).
|
// This is consistent with Adobe Reader (fixes issue9252.pdf,
|
||||||
if (divideBy === 10 && sign === 0) {
|
// issue15604.pdf, bug1753983.pdf).
|
||||||
warn("Lexer.getNumber - treating a single decimal point as zero.");
|
info(`Lexer.getNumber - "${msg}".`);
|
||||||
return 0;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
throw new FormatError(
|
throw new FormatError(msg);
|
||||||
`Invalid number: ${String.fromCharCode(ch)} (charCode ${ch})`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sign = sign || 1;
|
sign = sign || 1;
|
||||||
|
1
test/pdfs/issue15604.pdf.link
Normal file
1
test/pdfs/issue15604.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
https://github.com/mozilla/pdf.js/files/9832017/SP_Page1.pdf
|
@ -288,6 +288,13 @@
|
|||||||
"link": true,
|
"link": true,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{ "id": "issue15604",
|
||||||
|
"file": "pdfs/issue15604.pdf",
|
||||||
|
"md5": "505040e5634434ae97118a4c39bf27e5",
|
||||||
|
"rounds": 1,
|
||||||
|
"link": true,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{ "id": "bug921760",
|
{ "id": "bug921760",
|
||||||
"file": "pdfs/bug921760.pdf",
|
"file": "pdfs/bug921760.pdf",
|
||||||
"md5": "1aa136d786a65b0d7cce7bdb3c58c6c3",
|
"md5": "1aa136d786a65b0d7cce7bdb3c58c6c3",
|
||||||
|
@ -151,17 +151,17 @@ describe("parser", function () {
|
|||||||
expect(plusLexer.getNumber()).toEqual(205.88);
|
expect(plusLexer.getNumber()).toEqual(205.88);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should treat a single decimal point, or minus sign, as zero", function () {
|
it("should treat a single decimal point, or minus/plus sign, as zero", function () {
|
||||||
const dotInput = new StringStream(".");
|
const validNums = [".", "-", "+", "-.", "+.", "-\r\n.", "+\r\n."];
|
||||||
const dotLexer = new Lexer(dotInput);
|
for (const number of validNums) {
|
||||||
expect(dotLexer.getNumber()).toEqual(0);
|
const validInput = new StringStream(number);
|
||||||
|
const validLexer = new Lexer(validInput);
|
||||||
|
|
||||||
const minusInput = new StringStream("-");
|
expect(validLexer.getNumber()).toEqual(0);
|
||||||
const minusLexer = new Lexer(minusInput);
|
}
|
||||||
expect(minusLexer.getNumber()).toEqual(0);
|
|
||||||
|
|
||||||
const numbers = ["..", "-.", "+.", "-\r\n.", "+\r\n."];
|
const invalidNums = ["..", ".-", ".+"];
|
||||||
for (const number of numbers) {
|
for (const number of invalidNums) {
|
||||||
const invalidInput = new StringStream(number);
|
const invalidInput = new StringStream(number);
|
||||||
const invalidLexer = new Lexer(invalidInput);
|
const invalidLexer = new Lexer(invalidInput);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user