mozilla/pdf.js · error · JpegError

missing required Quantization Table.

Error message

missing required Quantization Table.

What it means

Thrown by quantizeAndInverse() before performing the inverse DCT on an 8x8 block. Each component must have a quantizationTable (loaded from a DQT marker) to dequantize coefficients; if component.quantizationTable is falsy the function cannot proceed. It signals that the component's quantizationId references a table slot that was never populated.

Source

Thrown at src/core/jpg.js:474

  }

  return offset - startOffset;
}

// A port of poppler's IDCT method which in turn is taken from:
//   Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
//   'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
//   IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
//   988-991.
function quantizeAndInverse(component, blockBufferOffset, p) {
  const qt = component.quantizationTable,
    blockData = component.blockData;
  let v0, v1, v2, v3, v4, v5, v6, v7;
  let p0, p1, p2, p3, p4, p5, p6, p7;
  let t;

  if (!qt) {
    throw new JpegError("missing required Quantization Table.");
  }

  // inverse DCT on rows
  for (let row = 0; row < 64; row += 8) {
    // gather block data
    p0 = blockData[blockBufferOffset + row];
    p1 = blockData[blockBufferOffset + row + 1];
    p2 = blockData[blockBufferOffset + row + 2];
    p3 = blockData[blockBufferOffset + row + 3];
    p4 = blockData[blockBufferOffset + row + 4];
    p5 = blockData[blockBufferOffset + row + 5];
    p6 = blockData[blockBufferOffset + row + 6];
    p7 = blockData[blockBufferOffset + row + 7];

    // dequant p0
    p0 *= qt[row];

    // check for all-zero AC coefficients

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Inspect the JPEG markers (e.g. with jpeginfo -d or a hex dump) and confirm a DQT exists for each quantizationId referenced in the SOF.
  2. If the table is missing, the stream is corrupt; re-export the image or obtain a valid copy.
  3. Catch JpegError at the rendering boundary and substitute a fallback image so the rest of the page still renders.
Defensive patterns

Strategy: try-catch

Validate before calling

// Confirm every quantizationId referenced in the SOF has a matching DQT slot
function hasAllQuantTables(data) {
  const ids = new Set();
  const missing = new Set();
  // crude marker scan — for illustration
  for (let i = 0; i < data.length - 1; i++) {
    if (data[i] === 0xff && data[i+1] === 0xdb) { ids.add(data[i+5] & 15); }
    if (data[i] === 0xff && (data[i+1] === 0xc0 || data[i+1] === 0xc2)) {
      const n = data[i+9]; for (let k=0;k<n;k++){ if(!ids.has(data[i+11+k*3+2])) missing.add(data[i+11+k*3+2]); }
    }
  }
  return missing.size === 0;
}

Try / catch

try {
  jpegImg.parse(data);
  pixels = jpegImg.getData({ width, height });
} catch (e) {
  if (e.name === 'JpegError' && /Quantization Table/.test(e.message)) { pixels = null; }
  throw e;
}

Prevention

When it happens

Trigger: Reached during block-level IDCT when a component's quantizationTable is null/undefined. Happens if the JPEG's SOF references a quantizationId for which no DQT (0xFFDB) marker was ever emitted, or the DQT was lost/truncated. Note: parse() assigns quantizationTable post-parse (line ~1179) specifically to tolerate DQT-after-SOF ordering, so this error means the table is genuinely absent.

Common situations: A JPEG inside a PDF where the DQT marker was stripped or the quantizationId in the SOF doesn't match any defined table. Also seen with minimally/incorrectly hand-crafted JPEG streams or when a PDF producer omits required tables.

Related errors


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