{"record":{"id":"1160a35d3fd76524","repo":"mozilla/pdf.js","slug":"only-single-frame-jpegs-supported","errorCode":null,"errorMessage":"Only single frame JPEGs supported","messagePattern":"Only single frame JPEGs supported","errorType":"exception","errorClass":"JpegError","httpStatus":null,"severity":"error","filePath":"src/core/jpg.js","lineNumber":1003,"sourceCode":"            } 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);\n          offset += 2;\n          frame.scanLines = dnlScanLines || sofScanLines;\n          frame.samplesPerLine = view.getUint16(offset);\n          offset += 2;\n          frame.components = [];\n          frame.componentIds = {};\n          const componentsCount = data[offset++];\n          let maxH = 0,\n            maxV = 0;\n          for (i = 0; i < componentsCount; i++) {","sourceCodeStart":985,"sourceCodeEnd":1021,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/jpg.js#L985-L1021","documentation":"Thrown by parse() if a SOF (Start-Of-Frame) marker (0xFFC0/C1/C2) is encountered when a frame has already been established. PDF.js only supports single-frame (non-hierarchical) JPEGs; a second SOF indicates hierarchical or animated JPEG which the decoder cannot handle.","triggerScenarios":"The marker loop sees a second SOFn marker after `frame` is already set. The guard `if (frame)` at the top of the SOFn case triggers the throw.","commonSituations":"Hierarchical-mode JPEG (rare), or a JPEG stream that accidentally concatenated two images. Some motion-JPEG or multi-frame containers embed multiple SOFs. Almost never seen in well-formed PDFs.","solutions":["Re-encode the image as a single-frame baseline or progressive JPEG.","If hierarchical JPEG is genuinely needed, pre-flatten it with an external tool before embedding.","Catch JpegError and fall back to a placeholder or external decoder."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { jpegImg.parse(data); }\ncatch (e) { if (e.name === 'JpegError' && /single frame/.test(e.message)) { /* multi-frame JPEG unsupported */ } else throw e; }","preventionTips":["Re-encode hierarchical/multi-frame JPEGs as single-frame baseline or progressive before embedding.","Pre-flatten with an external tool if hierarchical JPEG is required.","Catch JpegError at render time to substitute a fallback."],"tags":["jpeg","format-validation","image-decoding"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}