diff --git a/src/core/image.js b/src/core/image.js index 454671fa0..b84a6d51f 100644 --- a/src/core/image.js +++ b/src/core/image.js @@ -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, diff --git a/test/pdfs/issue19611.pdf.link b/test/pdfs/issue19611.pdf.link new file mode 100644 index 000000000..783cb9736 --- /dev/null +++ b/test/pdfs/issue19611.pdf.link @@ -0,0 +1 @@ +https://github.com/user-attachments/files/19102190/test.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 259f8fa04..52e7d8b38 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -3913,6 +3913,14 @@ "rounds": 1, "type": "eq" }, + { + "id": "issue19611", + "file": "pdfs/issue19611.pdf", + "md5": "169dc6df1c43dcb4659b2ddb6a4b39e4", + "rounds": 1, + "link": true, + "type": "eq" + }, { "id": "issue1127-text", "file": "pdfs/issue1127.pdf",