mozilla/pdf.js · error · JpxError

${errorMessages}

Error message

${errorMessages}

What it means

Thrown by JpxImage.decode() when the OpenJPEG WASM _jp2_decode returns nonzero (decode failure) and the module surfaced a non-empty errorMessages string. The WASM-side error text is wrapped in a JpxError. This is the structured-failure path: OpenJPEG parsed enough to emit a diagnostic.

Source

Thrown at src/core/jpx.js:68

    let ptr;

    try {
      const size = bytes.length;
      ptr = module._malloc(size);
      module.writeArrayToMemory(bytes, ptr);
      const ret = module._jp2_decode(
        ptr,
        size,
        numComponents > 0 ? numComponents : 0,
        !!isIndexedColormap,
        !!smaskInData,
        reducePower
      );
      if (ret) {
        const { errorMessages } = module;
        if (errorMessages) {
          delete module.errorMessages;
          throw new JpxError(errorMessages);
        }
        throw new JpxError("Unknown error");
      }
      const { imageData } = module;
      module.imageData = null;

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

  static parseImageProperties(stream) {
    if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("IMAGE_DECODERS")) {
      if (stream instanceof ArrayBuffer || ArrayBuffer.isView(stream)) {
        stream = new Stream(stream);

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Read the wrapped errorMessages text — it usually names the failing marker/component.
  2. Validate the JPEG2000 with a standalone OpenJPEG tool (opj_decompress) to confirm corruption.
  3. Ensure the PDF stream was decrypted and all filters before JPXDecode were applied.
  4. Catch JpxError and fall back to a placeholder image.
Defensive patterns

Strategy: try-catch

Try / catch

try { imageData = await JpxImage.instance.decode(bytes); }
catch (e) {
  if (e.name === 'JpxError') { console.warn('JPX decode failed:', e.message); imageData = null; }
  else throw e;
}

Prevention

When it happens

Trigger: Calling jpxImage.decode(bytes, opts) where bytes is a malformed/unusual JPEG2000 codestream or JP2 container that OpenJPEG rejects with an error message (e.g. invalid SIZ, unsupported Part-2 features, truncated codestream).

Common situations: A corrupt or partially-downloaded JPX stream in a PDF, a JPEG2000 image using features OpenJPEG doesn't support, or an encrypted stream passed before decryption. The errorMessages field typically contains the opj_xxx C-level reason.

Related errors


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