mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-07 17:05:38 +02:00
Merge pull request #18646 from Snuffleupagus/issue-18645
Support an odd number of digits in hexadecimal strings (issue 18645)
This commit is contained in:
commit
584fef5823
5 changed files with 28 additions and 20 deletions
|
@ -1163,8 +1163,8 @@ class Lexer {
|
||||||
const strBuf = this.strBuf;
|
const strBuf = this.strBuf;
|
||||||
strBuf.length = 0;
|
strBuf.length = 0;
|
||||||
let ch = this.currentChar;
|
let ch = this.currentChar;
|
||||||
let isFirstHex = true;
|
let firstDigit = -1,
|
||||||
let firstDigit, secondDigit;
|
digit = -1;
|
||||||
this._hexStringNumWarn = 0;
|
this._hexStringNumWarn = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -1178,26 +1178,25 @@ class Lexer {
|
||||||
ch = this.nextChar();
|
ch = this.nextChar();
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
if (isFirstHex) {
|
digit = toHexDigit(ch);
|
||||||
firstDigit = toHexDigit(ch);
|
if (digit === -1) {
|
||||||
if (firstDigit === -1) {
|
this._hexStringWarn(ch);
|
||||||
this._hexStringWarn(ch);
|
} else if (firstDigit === -1) {
|
||||||
ch = this.nextChar();
|
firstDigit = digit;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
secondDigit = toHexDigit(ch);
|
strBuf.push(String.fromCharCode((firstDigit << 4) | digit));
|
||||||
if (secondDigit === -1) {
|
firstDigit = -1;
|
||||||
this._hexStringWarn(ch);
|
|
||||||
ch = this.nextChar();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
|
|
||||||
}
|
}
|
||||||
isFirstHex = !isFirstHex;
|
|
||||||
ch = this.nextChar();
|
ch = this.nextChar();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// According to the PDF spec, section "7.3.4.3 Hexadecimal Strings":
|
||||||
|
// "If the final digit of a hexadecimal string is missing—that is, if there
|
||||||
|
// is an odd number of digits—the final digit shall be assumed to be 0."
|
||||||
|
if (firstDigit !== -1) {
|
||||||
|
strBuf.push(String.fromCharCode(firstDigit << 4));
|
||||||
|
}
|
||||||
return strBuf.join("");
|
return strBuf.join("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
|
@ -564,6 +564,7 @@
|
||||||
!poppler-90-0-fuzzed.pdf
|
!poppler-90-0-fuzzed.pdf
|
||||||
!issue14415.pdf
|
!issue14415.pdf
|
||||||
!issue14307.pdf
|
!issue14307.pdf
|
||||||
|
!issue18645.pdf
|
||||||
!issue14497.pdf
|
!issue14497.pdf
|
||||||
!bug1799927.pdf
|
!bug1799927.pdf
|
||||||
!issue14502.pdf
|
!issue14502.pdf
|
||||||
|
|
BIN
test/pdfs/issue18645.pdf
Normal file
BIN
test/pdfs/issue18645.pdf
Normal file
Binary file not shown.
|
@ -7986,6 +7986,13 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "issue18645",
|
||||||
|
"file": "pdfs/issue18645.pdf",
|
||||||
|
"md5": "ad05b63db4f21f612adb0900093a3e34",
|
||||||
|
"rounds": 1,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "bug857031",
|
"id": "bug857031",
|
||||||
"file": "pdfs/bug857031.pdf",
|
"file": "pdfs/bug857031.pdf",
|
||||||
|
|
|
@ -201,11 +201,12 @@ describe("parser", function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getHexString", function () {
|
describe("getHexString", function () {
|
||||||
it("should not throw exception on bad input", function () {
|
it("should handle an odd number of digits", function () {
|
||||||
// '7 0 2 15 5 2 2 2 4 3 2 4' should be parsed as '70 21 55 22 24 32'.
|
// '7 0 2 15 5 2 2 2 4 3 2 4' should be parsed as
|
||||||
|
// '70 21 55 22 24 32 40'.
|
||||||
const input = new StringStream("<7 0 2 15 5 2 2 2 4 3 2 4>");
|
const input = new StringStream("<7 0 2 15 5 2 2 2 4 3 2 4>");
|
||||||
const lexer = new Lexer(input);
|
const lexer = new Lexer(input);
|
||||||
expect(lexer.getHexString()).toEqual('p!U"$2');
|
expect(lexer.getHexString()).toEqual('p!U"$2@');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue