{"record":{"id":"1d80a968bd20a9f9","repo":"mozilla/pdf.js","slug":"invalid-image-width-width-or-height-height","errorCode":null,"errorMessage":"Invalid image width: ${width} or height: ${height}","messagePattern":"Invalid image width: (.+?) or height: (.+?)","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/image.js","lineNumber":159,"sourceCode":"      Number.isInteger(image.width) &&\n      image.width > 0 &&\n      Number.isInteger(image.height) &&\n      image.height > 0 &&\n      (image.width !== width || image.height !== height)\n    ) {\n      warn(\n        \"PDFImage - using the Width/Height of the image data, \" +\n          \"rather than the image dictionary.\"\n      );\n      width = image.width;\n      height = image.height;\n    } else {\n      const validWidth = typeof width === \"number\" && width > 0,\n        validHeight = typeof height === \"number\" && height > 0;\n\n      if (!validWidth || !validHeight) {\n        if (!image.fallbackDims) {\n          throw new FormatError(\n            `Invalid image width: ${width} or height: ${height}`\n          );\n        }\n        warn(\n          \"PDFImage - using the Width/Height of the parent image, for SMask/Mask data.\"\n        );\n        if (!validWidth) {\n          width = image.fallbackDims.width;\n        }\n        if (!validHeight) {\n          height = image.fallbackDims.height;\n        }\n      }\n    }\n    this.width = width;\n    this.height = height;\n\n    this.interpolate = dict.get(\"I\", \"Interpolate\");","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/image.js#L141-L177","documentation":"Thrown by the PDFImage constructor when neither the image dictionary's Width/Height nor the underlying stream's width/height is a positive number, and no parent fallbackDims are available to inherit from. Width and Height are mandatory for any PDF image object (PDF 32000-1 §8.9).","triggerScenarios":"An inline or XObject image whose /Width and/or /Height is missing, zero, negative, or non-numeric, and the image is not an SMask/Mask child (no fallbackDims). Reached while rendering any page that draws the bad image.","commonSituations":"Corrupt image XObjects from damaged PDFs; images whose Dimensions were lost during a copy/merge; PDFs produced by buggy scanners that omit the entries. Most common with inline images in content streams.","solutions":["Regenerate or repair the PDF so every image XObject has positive integer /Width and /Height.","Run qpdf --check or mutool clean to detect and repair broken image objects.","Catch FormatError at render time and skip the image while continuing the page.","If the image is yours, ensure the writer emits Width/Height as required integers."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// If you build image dicts yourself, validate before writing:\nfunction imageDimsValid(w, h) {\n  return Number.isInteger(w) && w > 0 && Number.isInteger(h) && h > 0;\n}","typeGuard":"function isPositiveIntegerDimensions(width, height) {\n  return Number.isInteger(width) && Number.isInteger(height) &&\n    width > 0 && height > 0;\n}","tryCatchPattern":"try { await page.render({ canvasContext }).promise; }\ncatch (err) {\n  if (/Invalid image width/.test(err?.message || '')) {\n    console.warn('Image missing valid Width/Height; skipping image.');\n  } else throw err;\n}","preventionTips":["Always write positive integer /Width and /Height on every image XObject when generating PDFs.","Run qpdf --check or mutool clean on incoming PDFs to detect damaged images.","Render per-page in try/catch to contain the failure."],"tags":["pdf","image","parsing","malformed-pdf","dimensions"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}