{"record":{"id":"82294cb14fdc9525","repo":"wmjordan/PDFPatcher","slug":"exif-data-not-found","errorCode":null,"errorMessage":"Exif data not found","messagePattern":"Exif data not found","errorType":"exception","errorClass":"ExifLibException","httpStatus":null,"severity":"warning","filePath":"App/Processor/Imaging/JpgHelper.cs","lineNumber":408,"sourceCode":"\t\t\t\t\t_stream.Seek(dataLength - 2, SeekOrigin.Current);\r\n\t\t\t\t}\r\n\r\n\t\t\t\t// It's only success if we found the 0xFFE1 marker\r\n\t\t\t\tif (markerStart != 0xFF || markerNumber != 0xE1)\r\n\t\t\t\t\tthrow new ExifLibException(\"Could not find Exif data block\");\r\n\t\t\t}\r\n\r\n\t\t\t/// <summary>\r\n\t\t\t/// Reads through the Exif data and builds an index of all Exif tags in the document\r\n\t\t\t/// </summary>\r\n\t\t\t/// <returns></returns>\r\n\t\t\tprivate void CreateTagIndex() {\r\n\t\t\t\t// The next 4 bytes are the size of the Exif data.\r\n\t\t\t\tReadUShort();\r\n\r\n\t\t\t\t// Next is the Exif data itself. It starts with the ASCII \"Exif\" followed by 2 zero bytes.\r\n\t\t\t\tif (ReadString(4) != \"Exif\")\r\n\t\t\t\t\tthrow new ExifLibException(\"Exif data not found\");\r\n\r\n\t\t\t\t// 2 zero bytes\r\n\t\t\t\tif (ReadUShort() != 0)\r\n\t\t\t\t\tthrow new ExifLibException(\"Malformed Exif data\");\r\n\r\n\t\t\t\t// We're now into the TIFF format\r\n\t\t\t\t_tiffHeaderStart = _stream.Position;\r\n\r\n\t\t\t\t// What byte align will be used for the TIFF part of the document? II for Intel, MM for Motorola\r\n\t\t\t\t_isLittleEndian = ReadString(2) == \"II\";\r\n\r\n\t\t\t\t// Next 2 bytes are always the same.\r\n\t\t\t\tif (ReadUShort() != 0x002A)\r\n\t\t\t\t\tthrow new ExifLibException(\"Error in TIFF data\");\r\n\r\n\t\t\t\t// Get the offset to the IFD (image file directory)\r\n\t\t\t\tvar ifdOffset = ReadUint();\r\n\r","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/wmjordan/PDFPatcher/blob/4782bbd9ada850b56258f29999b7a1c9076c9b1b/App/Processor/Imaging/JpgHelper.cs#L390-L426","documentation":"JpgHelper.CreateTagIndex throws ExifLibException('Exif data not found') when, after locating the APP1 segment, the first 4 bytes of its payload are not the ASCII string 'Exif'. The APP1 marker is present but the content is not an Exif block (could be XMP or another APP1 payload).","triggerScenarios":"A JPEG whose APP1 segment carries non-Exif data — most commonly XMP metadata (which also uses APP1 but starts with 'http://ns.adobe.com/xap/...'), or a non-standard APP1 payload. The reader found 0xFFE1 but the header signature check fails.","commonSituations":"Modern JPEGs with XMP metadata in APP1 instead of (or before) Exif; images processed by Adobe tools; JPEGs where Exif was replaced by XMP; malformed APP1 content.","solutions":["Catch ExifLibException around CreateTagIndex and treat it as 'no Exif available'.","Before parsing, sniff the APP1 payload for the 'Exif' signature and skip if absent (the APP1 may be XMP).","Use a more robust Exif/XMP library that distinguishes APP1 payload types."],"exampleFix":"// before\nif (ReadString(4) != \"Exif\")\n  throw new ExifLibException(\"Exif data not found\");\n\n// after\nif (ReadString(4) != \"Exif\") {\n  // APP1 is present but is not Exif (likely XMP); return empty catalogue\n  _ifd0Catalogue = new Dictionary<ushort, long>();\n  return;\n}","handlingStrategy":"try-catch","validationCode":"// Inspect APP1 payload head for 'Exif' before deep parsing.","typeGuard":"// APP1 is Exif only if payload starts with ASCII \"Exif\"","tryCatchPattern":"try { CreateTagIndex(); }\ncatch (ExifLibException) { _ifd0Catalogue = new Dictionary<ushort, long>(); }","preventionTips":["Distinguish XMP APP1 from Exif APP1 by payload signature.","Use a library that handles both APP1 payload types.","Catch ExifLibException and degrade to empty metadata."],"tags":["image","jpeg","exif","parsing","file-format"],"backgroundTag":null,"analyzedSha":"4782bbd9ada850b56258f29999b7a1c9076c9b1b","analyzedAt":"2026-08-13T17:44:50.812Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}