{"record":{"id":"93c8192fbd9506ba","repo":"mozilla/pdf.js","slug":"dqt-invalid-table-spec","errorCode":null,"errorMessage":"DQT - invalid table spec","messagePattern":"DQT - invalid table spec","errorType":"exception","errorClass":"JpegError","httpStatus":null,"severity":"error","filePath":"src/core/jpg.js","lineNumber":993,"sourceCode":"          let z;\n          while (offset < quantizationTablesEnd) {\n            const quantizationTableSpec = data[offset++];\n            const tableData = new Uint16Array(64);\n            if (quantizationTableSpec >> 4 === 0) {\n              // 8 bit values\n              for (j = 0; j < 64; j++) {\n                z = dctZigZag[j];\n                tableData[z] = data[offset++];\n              }\n            } else if (quantizationTableSpec >> 4 === 1) {\n              // 16 bit values\n              for (j = 0; j < 64; j++) {\n                z = dctZigZag[j];\n                tableData[z] = view.getUint16(offset);\n                offset += 2;\n              }\n            } else {\n              throw new JpegError(\"DQT - invalid table spec\");\n            }\n            quantizationTables[quantizationTableSpec & 15] = tableData;\n          }\n          break;\n\n        case 0xffc0: // SOF0 (Start of Frame, Baseline DCT)\n        case 0xffc1: // SOF1 (Start of Frame, Extended DCT)\n        case 0xffc2: // SOF2 (Start of Frame, Progressive DCT)\n          if (frame) {\n            throw new JpegError(\"Only single frame JPEGs supported\");\n          }\n          offset += 2; // Skip marker length.\n\n          frame = {};\n          frame.extended = fileMarker === 0xffc1;\n          frame.progressive = fileMarker === 0xffc2;\n          frame.precision = data[offset++];\n          const sofScanLines = view.getUint16(offset);","sourceCodeStart":975,"sourceCodeEnd":1011,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/jpg.js#L975-L1011","documentation":"Thrown while parsing a DQT (Define Quantization Table, 0xFFDB) marker. The high nibble of quantizationTableSpec selects precision: 0 = 8-bit values, 1 = 16-bit values. Any other nibble value is undefined by the JPEG standard and is rejected. Each table entry is 64 entries (8x8) in zig-zag order.","triggerScenarios":"During parse(), inside the 0xFFDB case, when quantizationTableSpec >> 4 is neither 0 nor 1. Indicates the DQT segment's table-spec byte is corrupt or an encoder used an unsupported precision.","commonSituations":"Corrupted DQT segment in an embedded JPEG, or a hand-crafted/non-standard encoder that set reserved precision bits. Rare in practice; usually signals byte-level damage.","solutions":["Hex-dump the DQT segment and verify each table-spec byte's upper nibble is 0 or 1.","Re-encode the JPEG with a compliant encoder (libjpeg, mozjpeg).","If the image is unrecoverable, catch JpegError and substitute a fallback."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { jpegImg.parse(data); }\ncatch (e) { if (e.name === 'JpegError' && /DQT/.test(e.message)) { /* corrupt DQT, placeholder */ } else throw e; }","preventionTips":["Validate JPEG markers with jpeginfo or a hex dump before relying on the stream.","Re-encode suspect JPEGs with a compliant encoder (mozjpeg/libjpeg).","Isolate decode failures so one bad image doesn't fail the page."],"tags":["jpeg","quantization","format-validation","corrupt-data"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}