1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

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:
Jonas Jenwald 2025-03-06 09:57:01 +01:00
parent 1bc98dfbd9
commit 10a99ea0a7
3 changed files with 37 additions and 5 deletions

View file

@ -140,11 +140,26 @@ class PDFImage {
);
width = image.width;
height = image.height;
}
if (width < 1 || height < 1) {
throw new FormatError(
`Invalid image width: ${width} or height: ${height}`
);
} else {
const validWidth = typeof width === "number" && width > 0,
validHeight = typeof height === "number" && height > 0;
if (!validWidth || !validHeight) {
if (!image.fallbackDims) {
throw new FormatError(
`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.height = height;
@ -244,6 +259,10 @@ class PDFImage {
}
if (smask) {
// Provide fallback width/height values for corrupt SMask images
// (see issue19611.pdf).
smask.fallbackDims ??= { width, height };
this.smask = new PDFImage({
xref,
res,
@ -260,6 +279,10 @@ class PDFImage {
if (!imageMask) {
warn("Ignoring /Mask in image without /ImageMask.");
} else {
// Provide fallback width/height values for corrupt Mask images
// (see issue19611.pdf).
mask.fallbackDims ??= { width, height };
this.mask = new PDFImage({
xref,
res,