{"record":{"id":"bba3fabae5446e1f","repo":"mozilla/pdf.js","slug":"jpegimage-parse-unknown-marker-filemarker-tos","errorCode":null,"errorMessage":"JpegImage.parse - unknown marker: ${fileMarker.toString(16)}","messagePattern":"JpegImage\\.parse - unknown marker: (.+?)","errorType":"exception","errorClass":"JpegError","httpStatus":null,"severity":"error","filePath":"src/core/jpg.js","lineNumber":1163,"sourceCode":"            /* currentPos = */ offset - 2,\n            /* startPos = */ offset - 3\n          );\n          if (nextFileMarker?.invalid) {\n            warn(\n              \"JpegImage.parse - unexpected data, current marker is: \" +\n                nextFileMarker.invalid\n            );\n            offset = nextFileMarker.offset;\n            break;\n          }\n          if (!nextFileMarker || offset >= maxOffset) {\n            warn(\n              \"JpegImage.parse - reached the end of the image data \" +\n                \"without finding an EOI marker (0xFFD9).\"\n            );\n            break markerLoop;\n          }\n          throw new JpegError(\n            \"JpegImage.parse - unknown marker: \" + fileMarker.toString(16)\n          );\n      }\n\n      if (offset < maxOffset) {\n        fileMarker = view.getUint16(offset);\n        offset += 2;\n      } else {\n        fileMarker = 0;\n      }\n    }\n\n    if (!frame) {\n      throw new JpegError(\"JpegImage.parse - no frame data found.\");\n    }\n    this.width = frame.samplesPerLine;\n    this.height = frame.scanLines;\n    this.jfif = jfif;","sourceCodeStart":1145,"sourceCodeEnd":1181,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/jpg.js#L1145-L1181","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Note the marker hex in the message and check the JPEG spec — it may be a valid-but-unimplemented marker.","Validate the JPEG with a standard decoder; if it fails there too, the stream is corrupt.","Re-encode or obtain a clean copy of the image.","Catch JpegError at render time to avoid crashing the page."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { jpegImg.parse(data); }\ncatch (e) { if (e.name === 'JpegError' && /unknown marker/.test(e.message)) { /* unsupported marker */ } else throw e; }","preventionTips":["Decode suspect JPEGs with a reference decoder to confirm validity.","Re-encode with a standard encoder to remove proprietary/unimplemented markers.","Catch JpegError and render a placeholder for unsupported images."],"tags":["jpeg","format-validation","image-decoding","corrupt-data"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}