{"record":{"id":"1a4d5540b8fce213","repo":"mozilla/pdf.js","slug":"missing-required-quantization-table","errorCode":null,"errorMessage":"missing required Quantization Table.","messagePattern":"missing required Quantization Table\\.","errorType":"exception","errorClass":"JpegError","httpStatus":null,"severity":"error","filePath":"src/core/jpg.js","lineNumber":474,"sourceCode":"  }\n\n  return offset - startOffset;\n}\n\n// A port of poppler's IDCT method which in turn is taken from:\n//   Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,\n//   'Practical Fast 1-D DCT Algorithms with 11 Multiplications',\n//   IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,\n//   988-991.\nfunction quantizeAndInverse(component, blockBufferOffset, p) {\n  const qt = component.quantizationTable,\n    blockData = component.blockData;\n  let v0, v1, v2, v3, v4, v5, v6, v7;\n  let p0, p1, p2, p3, p4, p5, p6, p7;\n  let t;\n\n  if (!qt) {\n    throw new JpegError(\"missing required Quantization Table.\");\n  }\n\n  // inverse DCT on rows\n  for (let row = 0; row < 64; row += 8) {\n    // gather block data\n    p0 = blockData[blockBufferOffset + row];\n    p1 = blockData[blockBufferOffset + row + 1];\n    p2 = blockData[blockBufferOffset + row + 2];\n    p3 = blockData[blockBufferOffset + row + 3];\n    p4 = blockData[blockBufferOffset + row + 4];\n    p5 = blockData[blockBufferOffset + row + 5];\n    p6 = blockData[blockBufferOffset + row + 6];\n    p7 = blockData[blockBufferOffset + row + 7];\n\n    // dequant p0\n    p0 *= qt[row];\n\n    // check for all-zero AC coefficients","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/jpg.js#L456-L492","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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.","If the table is missing, the stream is corrupt; re-export the image or obtain a valid copy.","Catch JpegError at the rendering boundary and substitute a fallback image so the rest of the page still renders."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Confirm every quantizationId referenced in the SOF has a matching DQT slot\nfunction hasAllQuantTables(data) {\n  const ids = new Set();\n  const missing = new Set();\n  // crude marker scan — for illustration\n  for (let i = 0; i < data.length - 1; i++) {\n    if (data[i] === 0xff && data[i+1] === 0xdb) { ids.add(data[i+5] & 15); }\n    if (data[i] === 0xff && (data[i+1] === 0xc0 || data[i+1] === 0xc2)) {\n      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]); }\n    }\n  }\n  return missing.size === 0;\n}","typeGuard":null,"tryCatchPattern":"try {\n  jpegImg.parse(data);\n  pixels = jpegImg.getData({ width, height });\n} catch (e) {\n  if (e.name === 'JpegError' && /Quantization Table/.test(e.message)) { pixels = null; }\n  throw e;\n}","preventionTips":["Ensure every quantizationId in the SOF has a corresponding DQT marker before embedding.","Use standard encoders that always emit required DQTs.","Catch JpegError and render a placeholder so the page isn't blocked."],"tags":["jpeg","quantization","image-decoding","corrupt-data"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}