{"record":{"id":"0e5fd655bdd53d6a","repo":"wmjordan/PDFPatcher","slug":"could-not-find-exif-data-block","errorCode":null,"errorMessage":"Could not find Exif data block","messagePattern":"Could not find Exif data block","errorType":"exception","errorClass":"ExifLibException","httpStatus":null,"severity":"warning","filePath":"App/Processor/Imaging/JpgHelper.cs","lineNumber":395,"sourceCode":"\t\t\tprivate void ReadToExifStart() {\r\n\t\t\t\t// The file has a number of blocks (Exif/JFIF), each of which\r\n\t\t\t\t// has a tag number followed by a length. We scan the document until the required tag (0xFFE1)\r\n\t\t\t\t// is found. All tags start with FF, so a non FF tag indicates an error.\r\n\r\n\t\t\t\t// Get the next tag.\r\n\t\t\t\tbyte markerStart;\r\n\t\t\t\tbyte markerNumber = 0;\r\n\t\t\t\twhile (((markerStart = _reader.ReadByte()) == 0xFF) && (markerNumber = _reader.ReadByte()) != 0xE1) {\r\n\t\t\t\t\t// Get the length of the data.\r\n\t\t\t\t\tushort dataLength = ReadUShort();\r\n\r\n\t\t\t\t\t// Jump to the end of the data (note that the size field includes its own size)!\r\n\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","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/wmjordan/PDFPatcher/blob/4782bbd9ada850b56258f29999b7a1c9076c9b1b/App/Processor/Imaging/JpgHelper.cs#L377-L413","documentation":"JpgHelper.ReadToExifStart throws ExifLibException('Could not find Exif data block') when scanning JPEG markers it never encounters the APP1 marker 0xFFE1 that introduces the Exif segment. The loop reads markers; if it exits without finding 0xFF/0xE1 (e.g. hit end of stream or a different marker pattern), the guard fires.","triggerScenarios":"Opening a JPEG that has no Exif metadata — a valid JPEG produced by a camera/tool that wrote JFIF without APP1 Exif, or a re-encoded/stripped JPEG. The scan reaches a non-FF byte or end of stream before the APP1 marker.","commonSituations":"Processing JPEGs from sources that don't embed Exif (web images, screenshots, software-generated images); a JPEG whose markers were stripped by an optimizer; a progressive or malformed JPEG where marker scanning goes astray.","solutions":["Treat 'no Exif' as an expected, non-fatal outcome: catch ExifLibException from ReadToExifStart and return empty Exif data.","Check for the APP1 marker presence before committing to full Exif parsing.","Skip Exif extraction for JPEGs known to be generated/optimized rather than photographed."],"exampleFix":"// before\nReadToExifStart(); // throws if no APP1\nCreateTagIndex();\n\n// after\ntry { ReadToExifStart(); CreateTagIndex(); }\ncatch (ExifLibException) {\n  // JPEG has no Exif block; return empty metadata\n  _ifd0Catalogue = new Dictionary<ushort, long>();\n}","handlingStrategy":"try-catch","validationCode":"// Cannot cheaply pre-validate marker presence without scanning;\n// wrap the call instead.","typeGuard":null,"tryCatchPattern":"try { ReadToExifStart(); CreateTagIndex(); }\ncatch (ExifLibException) { _ifd0Catalogue = new Dictionary<ushort, long>(); }","preventionTips":["Treat 'no Exif' as expected; do not let it abort processing.","Skip Exif extraction for known non-photographic JPEGs."],"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"}