mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-27 17:37:22 +02:00
Truncate too long /Decode map entries (issue 20668)
This commit is contained in:
parent
c5746949ac
commit
31b4612ac0
@ -116,6 +116,23 @@ function copyRgbaImage(src, dest, alpha01) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isDefaultDecodeHelper(decode, expectedLen) {
|
||||||
|
if (!Array.isArray(decode)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const decodeLen = decode.length;
|
||||||
|
|
||||||
|
if (decodeLen < expectedLen) {
|
||||||
|
warn("Decode map length is too short.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (decodeLen > expectedLen) {
|
||||||
|
info("Truncating too long decode map.");
|
||||||
|
decode.length = expectedLen;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
class ColorSpace {
|
class ColorSpace {
|
||||||
static #rgbBuf = new Uint8ClampedArray(3);
|
static #rgbBuf = new Uint8ClampedArray(3);
|
||||||
|
|
||||||
@ -185,8 +202,8 @@ class ColorSpace {
|
|||||||
/**
|
/**
|
||||||
* Refer to the static `ColorSpace.isDefaultDecode` method below.
|
* Refer to the static `ColorSpace.isDefaultDecode` method below.
|
||||||
*/
|
*/
|
||||||
isDefaultDecode(decodeMap, bpc) {
|
isDefaultDecode(decode, bpc) {
|
||||||
return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
|
return ColorSpace.isDefaultDecode(decode, this.numComps);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -322,11 +339,7 @@ class ColorSpace {
|
|||||||
* @param {number} numComps - Number of components the color space has.
|
* @param {number} numComps - Number of components the color space has.
|
||||||
*/
|
*/
|
||||||
static isDefaultDecode(decode, numComps) {
|
static isDefaultDecode(decode, numComps) {
|
||||||
if (!Array.isArray(decode)) {
|
if (isDefaultDecodeHelper(decode, numComps * 2)) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (numComps * 2 !== decode.length) {
|
|
||||||
warn("The decode map is not the correct length");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (let i = 0, ii = decode.length; i < ii; i += 2) {
|
for (let i = 0, ii = decode.length; i < ii; i += 2) {
|
||||||
@ -424,7 +437,7 @@ class PatternCS extends ColorSpace {
|
|||||||
this.base = baseCS;
|
this.base = baseCS;
|
||||||
}
|
}
|
||||||
|
|
||||||
isDefaultDecode(decodeMap, bpc) {
|
isDefaultDecode(decode, bpc) {
|
||||||
unreachable("Should not call PatternCS.isDefaultDecode");
|
unreachable("Should not call PatternCS.isDefaultDecode");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -489,19 +502,15 @@ class IndexedCS extends ColorSpace {
|
|||||||
return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
|
return this.base.getOutputLength(inputLength * this.base.numComps, alpha01);
|
||||||
}
|
}
|
||||||
|
|
||||||
isDefaultDecode(decodeMap, bpc) {
|
isDefaultDecode(decode, bpc) {
|
||||||
if (!Array.isArray(decodeMap)) {
|
if (isDefaultDecodeHelper(decode, 2)) {
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (decodeMap.length !== 2) {
|
|
||||||
warn("Decode map length is not correct");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (!Number.isInteger(bpc) || bpc < 1) {
|
if (!Number.isInteger(bpc) || bpc < 1) {
|
||||||
warn("Bits per component is not correct");
|
warn("Bits per component is not correct");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return decodeMap[0] === 0 && decodeMap[1] === (1 << bpc) - 1;
|
return decode[0] === 0 && decode[1] === (1 << bpc) - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1282,7 +1291,7 @@ class LabCS extends ColorSpace {
|
|||||||
return ((inputLength * (3 + alpha01)) / 3) | 0;
|
return ((inputLength * (3 + alpha01)) / 3) | 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
isDefaultDecode(decodeMap, bpc) {
|
isDefaultDecode(decode, bpc) {
|
||||||
// XXX: Decoding is handled with the lab conversion because of the strange
|
// XXX: Decoding is handled with the lab conversion because of the strange
|
||||||
// ranges that are used.
|
// ranges that are used.
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -873,4 +873,3 @@
|
|||||||
!Brotli-Prototype-FileA.pdf
|
!Brotli-Prototype-FileA.pdf
|
||||||
!bug2013793.pdf
|
!bug2013793.pdf
|
||||||
!bug2014080.pdf
|
!bug2014080.pdf
|
||||||
!issue20246.pdf
|
|
||||||
|
|||||||
1
test/pdfs/issue20668.pdf.link
Normal file
1
test/pdfs/issue20668.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
https://github.com/user-attachments/files/25338956/CE651A-_-HPP1102-specs.pdf
|
||||||
@ -13945,5 +13945,14 @@
|
|||||||
"link": true,
|
"link": true,
|
||||||
"lastPage": 1,
|
"lastPage": 1,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "issue20668",
|
||||||
|
"file": "pdfs/issue20668.pdf",
|
||||||
|
"md5": "70233922a9354c3708637902a8e22e70",
|
||||||
|
"rounds": 1,
|
||||||
|
"link": true,
|
||||||
|
"lastPage": 1,
|
||||||
|
"type": "eq"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user