mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Support an odd number of digits in hexadecimal strings (issue 18645)
See https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf#G6.1840792
This commit is contained in:
parent
908f453384
commit
8728f7f134
5 changed files with 28 additions and 20 deletions
|
@ -1163,8 +1163,8 @@ class Lexer {
|
|||
const strBuf = this.strBuf;
|
||||
strBuf.length = 0;
|
||||
let ch = this.currentChar;
|
||||
let isFirstHex = true;
|
||||
let firstDigit, secondDigit;
|
||||
let firstDigit = -1,
|
||||
digit = -1;
|
||||
this._hexStringNumWarn = 0;
|
||||
|
||||
while (true) {
|
||||
|
@ -1178,26 +1178,25 @@ class Lexer {
|
|||
ch = this.nextChar();
|
||||
continue;
|
||||
} else {
|
||||
if (isFirstHex) {
|
||||
firstDigit = toHexDigit(ch);
|
||||
if (firstDigit === -1) {
|
||||
this._hexStringWarn(ch);
|
||||
ch = this.nextChar();
|
||||
continue;
|
||||
}
|
||||
digit = toHexDigit(ch);
|
||||
if (digit === -1) {
|
||||
this._hexStringWarn(ch);
|
||||
} else if (firstDigit === -1) {
|
||||
firstDigit = digit;
|
||||
} else {
|
||||
secondDigit = toHexDigit(ch);
|
||||
if (secondDigit === -1) {
|
||||
this._hexStringWarn(ch);
|
||||
ch = this.nextChar();
|
||||
continue;
|
||||
}
|
||||
strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
|
||||
strBuf.push(String.fromCharCode((firstDigit << 4) | digit));
|
||||
firstDigit = -1;
|
||||
}
|
||||
isFirstHex = !isFirstHex;
|
||||
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("");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue