{"record":{"id":"27103f456de6d84b","repo":"wmjordan/PDFPatcher","slug":"error-in-tiff-data","errorCode":null,"errorMessage":"Error in TIFF data","messagePattern":"Error in TIFF data","errorType":"exception","errorClass":"ExifLibException","httpStatus":null,"severity":"warning","filePath":"App/Processor/Imaging/JpgHelper.cs","lineNumber":422,"sourceCode":"\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\n\t\t\t\t// Note that this offset is from the first byte of the TIFF header. Jump to the IFD.\r\n\t\t\t\t_stream.Position = ifdOffset + _tiffHeaderStart;\r\n\r\n\t\t\t\t// Catalogue this first IFD (there will be another IFD)\r\n\t\t\t\t_ifd0Catalogue = new Dictionary<ushort, long>();\r\n\t\t\t\tCatalogueIFD(ref _ifd0Catalogue);\r\n\r\n\t\t\t\t// The address to the IFD1 (the thumbnail IFD) is located immediately after the main IFD\r\n\t\t\t\t_ifd1Offset = ReadUint();\r\n\r\n\t\t\t\t// There's more data stored in the subifd, the offset to which is found in tag 0x8769.\r\n\t\t\t\t// As with all TIFF offsets, it will be relative to the first byte of the TIFF header.\r\n\t\t\t\tuint offset;\r\n\t\t\t\tif (!GetTagValue(_ifd0Catalogue, 0x8769, out offset))\r","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/wmjordan/PDFPatcher/blob/4782bbd9ada850b56258f29999b7a1c9076c9b1b/App/Processor/Imaging/JpgHelper.cs#L404-L440","documentation":"JpgHelper.CreateTagIndex throws ExifLibException('Error in TIFF data') when the 2-byte TIFF magic number immediately after the byte-order marker is not 0x002A. 0x002A is the fixed TIFF signature required by the Exif/TIFF structure; any other value means the TIFF header within the Exif block is invalid.","triggerScenarios":"A JPEG whose Exif block passes the 'Exif' signature and padding checks but whose embedded TIFF header has a wrong magic number (not 42/0x002A) — indicating corruption of the TIFF portion or a misidentified offset.","commonSituations":"A corrupt Exif/TIFF header inside an otherwise valid JPEG; byte-level damage to the Exif segment; a malformed Exif block from a non-conformant writer; truncation of the segment.","solutions":["Catch ExifLibException and treat the Exif block as unreadable, returning empty metadata.","Verify the byte-order (II/MM) alignment before reading the magic; a misread offset can also cause this.","Repair the JPEG with an Exif-aware tool that can rebuild the TIFF header.","Skip and log corrupt files in batch runs."],"exampleFix":"// before\nif (ReadUShort() != 0x002A)\n  throw new ExifLibException(\"Error in TIFF data\");\n\n// after\nif (ReadUShort() != 0x002A) {\n  Tracker.TraceMessage(Tracker.Category.Warning, \"TIFF 标头无效，跳过 Exif。\");\n  _ifd0Catalogue = new Dictionary<ushort, long>();\n  return;\n}","handlingStrategy":"try-catch","validationCode":"// TIFF magic check is internal; pre-validation requires parsing.\n// Wrap the call instead.","typeGuard":null,"tryCatchPattern":"try { CreateTagIndex(); }\ncatch (ExifLibException) { _ifd0Catalogue = new Dictionary<ushort, long>(); }","preventionTips":["Catch ExifLibException around CreateTagIndex.","Repair JPEGs with invalid TIFF headers.","Skip unreadable Exif in batch processing."],"tags":["image","jpeg","exif","tiff","parsing","corrupt-file"],"backgroundTag":null,"analyzedSha":"4782bbd9ada850b56258f29999b7a1c9076c9b1b","analyzedAt":"2026-08-13T17:44:50.812Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}