mozilla/pdf.js · error · Jbig2Error

Unknown error

Error message

Unknown error

What it means

Thrown by JBig2CCITTFaxImage.decode after _jbig2_decode/_ccitt_decode returned without populating module.imageData. The decoder ran but produced no output pixels, which the JS layer cannot interpret, so it surfaces a generic 'Unknown error'.

Source

Thrown at src/core/jbig2_ccittFax.js:74

          width,
          height,
          CCITTOptions.K,
          CCITTOptions.EndOfLine ? 1 : 0,
          CCITTOptions.EncodedByteAlign ? 1 : 0,
          CCITTOptions.BlackIs1 ? 1 : 0,
          CCITTOptions.Columns,
          CCITTOptions.Rows
        );
      } else {
        const globalsSize = globals ? globals.length : 0;
        if (globalsSize > 0) {
          globalsPtr = module._malloc(globalsSize);
          module.writeArrayToMemory(globals, globalsPtr);
        }
        module._jbig2_decode(ptr, size, width, height, globalsPtr, globalsSize);
      }
      if (!module.imageData) {
        throw new Jbig2Error("Unknown error");
      }
      const { imageData } = module;
      module.imageData = null;

      return imageData;
    } finally {
      if (ptr) {
        module._free(ptr);
      }
      if (globalsPtr) {
        module._free(globalsPtr);
      }
    }
  }
}

export { JBig2CCITTFaxImage, Jbig2Error };

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Verify the image's Width/Height and Globals are correct and match the encoded data (see errors 149/150).
  2. Re-encode the source image to a non-JBIG2 format if the stream is irreparable.
  3. Catch Jbig2Error at render time and skip the image while continuing the page.
  4. Report the file to pdf.js maintainers with the PDF for decoder diagnostics.
Defensive patterns

Strategy: try-catch

Validate before calling

// No reliable external pre-check; verify inputs that the wasm decoder depends on:
function jbig2InputsPlausible(bytes, width, height) {
  return bytes instanceof Uint8Array && bytes.length > 0 &&
    Number.isInteger(width) && width > 0 &&
    Number.isInteger(height) && height > 0;
}

Type guard

function hasValidJbig2Inputs(bytes, width, height) {
  return bytes instanceof Uint8Array && bytes.length > 0 &&
    Number.isInteger(width) && width > 0 && Number.isInteger(height) && height > 0;
}

Try / catch

try { await page.render({ canvasContext }).promise; }
catch (err) {
  if (err?.name === 'Jbig2Error' && err.message === 'Unknown error') {
    console.warn('JBIG2 decoder produced no output; skipping image.');
  } else throw err;
}

Prevention

When it happens

Trigger: The JBIG2/CCITT wasm decoder accepted the input but failed internally (corrupt stream, bad globals, mismatched width/height) without throwing, leaving module.imageData null. Reached during rendering of a JBIG2 or fax-encoded image.

Common situations: Damaged JBIG2 streams, mismatched /Globals, wrong width/height passed to decode (e.g. from a malformed image dict), or a wasm build bug. Hard to distinguish without the underlying wasm's own diagnostics.

Related errors


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