mozilla/pdf.js · error · JpegError

DQT - invalid table spec

Error message

DQT - invalid table spec

What it means

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.

Source

Thrown at src/core/jpg.js:993

          let z;
          while (offset < quantizationTablesEnd) {
            const quantizationTableSpec = data[offset++];
            const tableData = new Uint16Array(64);
            if (quantizationTableSpec >> 4 === 0) {
              // 8 bit values
              for (j = 0; j < 64; j++) {
                z = dctZigZag[j];
                tableData[z] = data[offset++];
              }
            } else if (quantizationTableSpec >> 4 === 1) {
              // 16 bit values
              for (j = 0; j < 64; j++) {
                z = dctZigZag[j];
                tableData[z] = view.getUint16(offset);
                offset += 2;
              }
            } else {
              throw new JpegError("DQT - invalid table spec");
            }
            quantizationTables[quantizationTableSpec & 15] = tableData;
          }
          break;

        case 0xffc0: // SOF0 (Start of Frame, Baseline DCT)
        case 0xffc1: // SOF1 (Start of Frame, Extended DCT)
        case 0xffc2: // SOF2 (Start of Frame, Progressive DCT)
          if (frame) {
            throw new JpegError("Only single frame JPEGs supported");
          }
          offset += 2; // Skip marker length.

          frame = {};
          frame.extended = fileMarker === 0xffc1;
          frame.progressive = fileMarker === 0xffc2;
          frame.precision = data[offset++];
          const sofScanLines = view.getUint16(offset);

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Hex-dump the DQT segment and verify each table-spec byte's upper nibble is 0 or 1.
  2. Re-encode the JPEG with a compliant encoder (libjpeg, mozjpeg).
  3. If the image is unrecoverable, catch JpegError and substitute a fallback.
Defensive patterns

Strategy: try-catch

Try / catch

try { jpegImg.parse(data); }
catch (e) { if (e.name === 'JpegError' && /DQT/.test(e.message)) { /* corrupt DQT, placeholder */ } else throw e; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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