{"record":{"id":"0ac6053f55e292e7","repo":"mozilla/pdf.js","slug":"bits-per-component-missing-in-image-this-imagem","errorCode":null,"errorMessage":"Bits per component missing in image: ${this.imageMask}","messagePattern":"Bits per component missing in image: (.+?)","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"error","filePath":"src/core/image.js","lineNumber":188,"sourceCode":"          height = image.fallbackDims.height;\n        }\n      }\n    }\n    this.width = width;\n    this.height = height;\n\n    this.interpolate = dict.get(\"I\", \"Interpolate\");\n    this.imageMask = dict.get(\"IM\", \"ImageMask\") || false;\n    this.matte = dict.get(\"Matte\") || false;\n\n    let bitsPerComponent = image.bitsPerComponent;\n    if (!bitsPerComponent) {\n      bitsPerComponent = dict.get(\"BPC\", \"BitsPerComponent\");\n      if (!bitsPerComponent) {\n        if (this.imageMask) {\n          bitsPerComponent = 1;\n        } else {\n          throw new FormatError(\n            `Bits per component missing in image: ${this.imageMask}`\n          );\n        }\n      }\n    }\n    this.bpc = bitsPerComponent;\n\n    if (!this.imageMask) {\n      let colorSpace = dict.getRaw(\"CS\") || dict.getRaw(\"ColorSpace\");\n      const hasColorSpace = !!colorSpace;\n\n      if (\n        this.jpxDecoderOptions?.smaskInData &&\n        dict.get(\"SMaskInData\") === 2\n      ) {\n        this.jpxPremultiplied = true;\n        if (this.matte) {\n          const matteColorSpace = ColorSpaceUtils.parse({","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/image.js#L170-L206","documentation":"Thrown by the PDFImage constructor when /BitsPerComponent is missing (and no bitsPerComponent was supplied on the image object) for a non-image-mask image. Image masks default to 1 bpc; regular images must declare BPC explicitly per PDF 32000-1 §8.9.","triggerScenarios":"A non-mask image dictionary that has neither /BPC nor /BitsPerComponent and is not an image mask (IM false). Reached while decoding any image draw operator referencing the affected XObject or inline image.","commonSituations":"PDFs from tools that omit BPC relying on a default; images corrupted during transmission; inline images where the BPC operand was dropped. Often seen alongside error 149 on the same broken image.","solutions":["Ensure every non-mask image in source PDFs declares /BitsPerComponent (commonly 8).","Repair the PDF with qpdf/mutool to restore missing entries where possible.","Catch FormatError and degrade by skipping the image.","Validate with Acrobat; report if Acrobat tolerates a default the spec disallows."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function imageHasBpc(dict) {\n  const bpc = dict.get?.('BPC', 'BitsPerComponent') ?? dict.get?.('BitsPerComponent');\n  return typeof bpc === 'number' && bpc > 0;\n}","typeGuard":"function isValidBitsPerComponent(bpc) {\n  return [1, 2, 4, 8, 16].includes(bpc);\n}","tryCatchPattern":"try { await page.render({ canvasContext }).promise; }\ncatch (err) {\n  if (/Bits per component missing/.test(err?.message || '')) {\n    console.warn('Image missing BitsPerComponent; skipping image.');\n  } else throw err;\n}","preventionTips":["Always declare /BitsPerComponent on non-mask images when authoring PDFs.","Validate PDFs with qpdf --check before distribution.","Isolate per-page rendering with try/catch."],"tags":["pdf","image","bits-per-component","parsing","malformed-pdf"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}