mozilla/pdf.js · error · JpegError

Duplicate EXIF-blocks found.

Error message

Duplicate EXIF-blocks found.

What it means

Thrown by canUseImageDecoder() while scanning APP1 segments. The EXIF spec allows exactly one APP1/Exif block; if a second segment matching the 'Exif\x00\x00' signature is found, the error fires. This guards the WebCodecs path which cannot handle multiple EXIF blobs.

Source

Thrown at src/core/jpg.js:847

          //       is fixed.
          const { appData, oldOffset, newOffset } = readDataBlock(
            data,
            view,
            offset
          );
          offset = newOffset;

          // 'Exif\x00\x00'
          if (
            appData[0] === 0x45 &&
            appData[1] === 0x78 &&
            appData[2] === 0x69 &&
            appData[3] === 0x66 &&
            appData[4] === 0 &&
            appData[5] === 0
          ) {
            if (exifOffsets) {
              throw new JpegError("Duplicate EXIF-blocks found.");
            }
            // Don't do the EXIF-block replacement here, see `JpegStream`,
            // since that can modify the original PDF document.
            exifOffsets = { exifStart: oldOffset + 6, exifEnd: newOffset };
          }
          fileMarker = view.getUint16(offset);
          offset += 2;
          continue;
        case 0xffc0: // SOF0 (Start of Frame, Baseline DCT)
        case 0xffc1: // SOF1 (Start of Frame, Extended DCT)
        case 0xffc2: // SOF2 (Start of Frame, Progressive DCT)
          // Skip marker length.
          // Skip precision.
          // Skip scanLines.
          // Skip samplesPerLine.
          numComponents = data[offset + (2 + 1 + 2 + 2)];
          break markerLoop;
        case 0xffff: // Fill bytes

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Strip duplicate EXIF segments from the JPEG using exiftool or jpegtran before embedding in the PDF.
  2. If you cannot modify the source, avoid the canUseImageDecoder fast-path and fall back to the software JPEG decoder (JpegImage.parse) which tolerates this.
  3. Report the producing tool as non-compliant with the EXIF/JEITA specification.
Defensive patterns

Strategy: try-catch

Try / catch

try { const r = JpegImage.canUseImageDecoder(data); }
catch (e) { if (e.name === 'JpegError' && /Duplicate EXIF/.test(e.message)) { /* use software decoder instead */ } else throw e; }

Prevention

When it happens

Trigger: canUseImageDecoder encounters two APP1 (0xFFE1) segments both beginning with the 6-byte 'Exif\x00\x00' signature. The exifOffsets variable is already set when the second match is detected.

Common situations: A JPEG that was re-saved or edited by tools that append a new EXIF block without removing the old one. Some camera/editing pipelines produce duplicate APP1 segments. Relatively rare in PDF-embedded images but possible.

Related errors


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