mozilla/pdf.js · error · JpegError

JpegImage.parse - unknown marker: ${fileMarker.toString(16)}

Error message

JpegImage.parse - unknown marker: ${fileMarker.toString(16)}

What it means

Thrown in the default case of parse()'s marker switch when an unrecognized marker is encountered and findNextFileMarker() cannot recover. findNextFileMarker searches for the next valid marker; if it returns null/valid-or-past-end without an 'invalid' recovery hint, the unknown marker is treated as fatal.

Source

Thrown at src/core/jpg.js:1163

            /* currentPos = */ offset - 2,
            /* startPos = */ offset - 3
          );
          if (nextFileMarker?.invalid) {
            warn(
              "JpegImage.parse - unexpected data, current marker is: " +
                nextFileMarker.invalid
            );
            offset = nextFileMarker.offset;
            break;
          }
          if (!nextFileMarker || offset >= maxOffset) {
            warn(
              "JpegImage.parse - reached the end of the image data " +
                "without finding an EOI marker (0xFFD9)."
            );
            break markerLoop;
          }
          throw new JpegError(
            "JpegImage.parse - unknown marker: " + fileMarker.toString(16)
          );
      }

      if (offset < maxOffset) {
        fileMarker = view.getUint16(offset);
        offset += 2;
      } else {
        fileMarker = 0;
      }
    }

    if (!frame) {
      throw new JpegError("JpegImage.parse - no frame data found.");
    }
    this.width = frame.samplesPerLine;
    this.height = frame.scanLines;
    this.jfif = jfif;

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Note the marker hex in the message and check the JPEG spec — it may be a valid-but-unimplemented marker.
  2. Validate the JPEG with a standard decoder; if it fails there too, the stream is corrupt.
  3. Re-encode or obtain a clean copy of the image.
  4. Catch JpegError at render time to avoid crashing the page.
Defensive patterns

Strategy: try-catch

Try / catch

try { jpegImg.parse(data); }
catch (e) { if (e.name === 'JpegError' && /unknown marker/.test(e.message)) { /* unsupported marker */ } else throw e; }

Prevention

When it happens

Trigger: A marker code not in the handled set (SOI/EOI/APP*/DQT/SOF/DHT/DRI/SOS/DNL/fill) appears, and findNextFileMarker doesn't return an .invalid offset to resume from, and offset hasn't reached maxOffset. The hex marker value is included in the message.

Common situations: A JPEG using markers PDF.js doesn't implement (e.g. COM/0xFFFE comment markers are handled via skipData, but some proprietary markers may not be), or corruption that looks like a marker. Most often the data is simply damaged.

Related errors


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