mozilla/pdf.js · error · FormatError

Bits per component missing in image: ${this.imageMask}

Error message

Bits per component missing in image: ${this.imageMask}

What it means

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.

Source

Thrown at src/core/image.js:188

          height = image.fallbackDims.height;
        }
      }
    }
    this.width = width;
    this.height = height;

    this.interpolate = dict.get("I", "Interpolate");
    this.imageMask = dict.get("IM", "ImageMask") || false;
    this.matte = dict.get("Matte") || false;

    let bitsPerComponent = image.bitsPerComponent;
    if (!bitsPerComponent) {
      bitsPerComponent = dict.get("BPC", "BitsPerComponent");
      if (!bitsPerComponent) {
        if (this.imageMask) {
          bitsPerComponent = 1;
        } else {
          throw new FormatError(
            `Bits per component missing in image: ${this.imageMask}`
          );
        }
      }
    }
    this.bpc = bitsPerComponent;

    if (!this.imageMask) {
      let colorSpace = dict.getRaw("CS") || dict.getRaw("ColorSpace");
      const hasColorSpace = !!colorSpace;

      if (
        this.jpxDecoderOptions?.smaskInData &&
        dict.get("SMaskInData") === 2
      ) {
        this.jpxPremultiplied = true;
        if (this.matte) {
          const matteColorSpace = ColorSpaceUtils.parse({

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Ensure every non-mask image in source PDFs declares /BitsPerComponent (commonly 8).
  2. Repair the PDF with qpdf/mutool to restore missing entries where possible.
  3. Catch FormatError and degrade by skipping the image.
  4. Validate with Acrobat; report if Acrobat tolerates a default the spec disallows.
Defensive patterns

Strategy: validation

Validate before calling

function imageHasBpc(dict) {
  const bpc = dict.get?.('BPC', 'BitsPerComponent') ?? dict.get?.('BitsPerComponent');
  return typeof bpc === 'number' && bpc > 0;
}

Type guard

function isValidBitsPerComponent(bpc) {
  return [1, 2, 4, 8, 16].includes(bpc);
}

Try / catch

try { await page.render({ canvasContext }).promise; }
catch (err) {
  if (/Bits per component missing/.test(err?.message || '')) {
    console.warn('Image missing BitsPerComponent; skipping image.');
  } else throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/0ac6053f55e292e7. Report an issue: GitHub.