mozilla/pdf.js · error · FormatError

IndexedCS - unrecognized lookup table: ${lookup}

Error message

IndexedCS - unrecognized lookup table: ${lookup}

What it means

Thrown while constructing an Indexed color space when the lookup table (the palette argument) is neither a BaseStream nor a JS string. pdf.js only accepts stream-backed or string palettes for /Indexed color spaces; any other type (number, Name, array, null) is rejected.

Source

Thrown at src/core/colorspace.js:495

class IndexedCS extends ColorSpace {
  #rgbLookup;

  constructor(base, highVal, lookup) {
    super("Indexed", 1);
    this.highVal = highVal;

    const count = highVal + 1;
    const length = base.numComps * count;
    const palette = new Uint8Array(length);

    if (lookup instanceof BaseStream) {
      palette.set(lookup.getBytes(length));
    } else if (typeof lookup === "string") {
      for (let i = 0; i < length; ++i) {
        palette[i] = lookup.charCodeAt(i);
      }
    } else {
      throw new FormatError(`IndexedCS - unrecognized lookup table: ${lookup}`);
    }

    this.#rgbLookup = new Uint8ClampedArray(count * 3);
    base.getRgbBuffer(
      palette,
      0,
      count,
      this.#rgbLookup,
      0,
      /* bits = */ 8,
      /* alpha01 = */ 0
    );
  }

  getRgbItem(src, srcOffset, dest, destOffset) {
    if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
      assert(
        dest instanceof Uint8ClampedArray,

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Repair or regenerate the PDF.
  2. Update pdf.js; newer versions resolve more indirect-reference cases correctly.
  3. Catch FormatError and let pdf.js fall back to a default color space for the image.
Defensive patterns

Strategy: try-catch

Type guard

import { BaseStream } from './base_stream.js';
function isValidLookup(lookup) {
  return lookup instanceof BaseStream || typeof lookup === 'string';
}

Try / catch

try {
  cs = ColorSpace.parse(res, xref, cs, pdfFunctionFactory);
} catch (e) {
  if (e instanceof FormatError && /unrecognized lookup table/.test(e.message)) {
    console.warn('Bad Indexed lookup table, falling back to default colorspace', e);
    cs = null;
  } else throw e;
}

Prevention

When it happens

Trigger: A PDF /Indexed colorspace whose lookup table is a number, Name, array, or null/undefined - typically from a malformed dictionary or an unresolved indirect object reference that yielded a non-stream scalar.

Common situations: Corrupt PDF; broken cross-reference table causing object resolution to return a wrong type; a custom PDF generator emitting the wrong object type for the palette.

Related errors


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