Let SMask/Mask images fallback to the parent image dimensions (issue 19611)
One of the images have a corrupt SMask, where the /Height-entry is bogus; see the excerpt below (via https://brendandahl.github.io/pdf.js.utils/browser/). ``` SMask (stream) [id: 17, gen: 0] ColorSpace = /DeviceGray Height = /Length Subtype = /Image Filter = /FlateDecode Type = /XObject Width = 157 Matte (array) BitsPerComponent = 8 Length = 3893 <view contents> download ``` Hence we enable SMask/Mask images to fallback to the parent image dimensions, and also add more validation of the width/height to get a better error message when that data is wrong.
This commit is contained in:
parent
1bc98dfbd9
commit
10a99ea0a7
@ -140,12 +140,27 @@ class PDFImage {
|
|||||||
);
|
);
|
||||||
width = image.width;
|
width = image.width;
|
||||||
height = image.height;
|
height = image.height;
|
||||||
}
|
} else {
|
||||||
if (width < 1 || height < 1) {
|
const validWidth = typeof width === "number" && width > 0,
|
||||||
|
validHeight = typeof height === "number" && height > 0;
|
||||||
|
|
||||||
|
if (!validWidth || !validHeight) {
|
||||||
|
if (!image.fallbackDims) {
|
||||||
throw new FormatError(
|
throw new FormatError(
|
||||||
`Invalid image width: ${width} or height: ${height}`
|
`Invalid image width: ${width} or height: ${height}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
warn(
|
||||||
|
"PDFImage - using the Width/Height of the parent image, for SMask/Mask data."
|
||||||
|
);
|
||||||
|
if (!validWidth) {
|
||||||
|
width = image.fallbackDims.width;
|
||||||
|
}
|
||||||
|
if (!validHeight) {
|
||||||
|
height = image.fallbackDims.height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
this.width = width;
|
this.width = width;
|
||||||
this.height = height;
|
this.height = height;
|
||||||
|
|
||||||
@ -244,6 +259,10 @@ class PDFImage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (smask) {
|
if (smask) {
|
||||||
|
// Provide fallback width/height values for corrupt SMask images
|
||||||
|
// (see issue19611.pdf).
|
||||||
|
smask.fallbackDims ??= { width, height };
|
||||||
|
|
||||||
this.smask = new PDFImage({
|
this.smask = new PDFImage({
|
||||||
xref,
|
xref,
|
||||||
res,
|
res,
|
||||||
@ -260,6 +279,10 @@ class PDFImage {
|
|||||||
if (!imageMask) {
|
if (!imageMask) {
|
||||||
warn("Ignoring /Mask in image without /ImageMask.");
|
warn("Ignoring /Mask in image without /ImageMask.");
|
||||||
} else {
|
} else {
|
||||||
|
// Provide fallback width/height values for corrupt Mask images
|
||||||
|
// (see issue19611.pdf).
|
||||||
|
mask.fallbackDims ??= { width, height };
|
||||||
|
|
||||||
this.mask = new PDFImage({
|
this.mask = new PDFImage({
|
||||||
xref,
|
xref,
|
||||||
res,
|
res,
|
||||||
|
|||||||
1
test/pdfs/issue19611.pdf.link
Normal file
1
test/pdfs/issue19611.pdf.link
Normal file
@ -0,0 +1 @@
|
|||||||
|
https://github.com/user-attachments/files/19102190/test.pdf
|
||||||
@ -3913,6 +3913,14 @@
|
|||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "issue19611",
|
||||||
|
"file": "pdfs/issue19611.pdf",
|
||||||
|
"md5": "169dc6df1c43dcb4659b2ddb6a4b39e4",
|
||||||
|
"rounds": 1,
|
||||||
|
"link": true,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "issue1127-text",
|
"id": "issue1127-text",
|
||||||
"file": "pdfs/issue1127.pdf",
|
"file": "pdfs/issue1127.pdf",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user