wmjordan/PDFPatcher · warning · ExifLibException

Error in TIFF data

Error message

Error in TIFF data

What it means

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.

Solutions

  1. Catch ExifLibException and treat the Exif block as unreadable, returning empty metadata.
  2. Verify the byte-order (II/MM) alignment before reading the magic; a misread offset can also cause this.
  3. Repair the JPEG with an Exif-aware tool that can rebuild the TIFF header.
  4. Skip and log corrupt files in batch runs.

Example fix

// before
if (ReadUShort() != 0x002A)
  throw new ExifLibException("Error in TIFF data");

// after
if (ReadUShort() != 0x002A) {
  Tracker.TraceMessage(Tracker.Category.Warning, "TIFF 标头无效,跳过 Exif。");
  _ifd0Catalogue = new Dictionary<ushort, long>();
  return;
}
Defensive patterns

Strategy: try-catch

Validate before calling

// TIFF magic check is internal; pre-validation requires parsing.
// Wrap the call instead.

Try / catch

try { CreateTagIndex(); }
catch (ExifLibException) { _ifd0Catalogue = new Dictionary<ushort, long>(); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of wmjordan/PDFPatcher@4782bbd9ad (2026-08-13). Data as JSON: /api/errors/27103f456de6d84b. Report an issue: GitHub.

Appendix: source

Thrown at App/Processor/Imaging/JpgHelper.cs:422

				ReadUShort();

				// Next is the Exif data itself. It starts with the ASCII "Exif" followed by 2 zero bytes.
				if (ReadString(4) != "Exif")
					throw new ExifLibException("Exif data not found");

				// 2 zero bytes
				if (ReadUShort() != 0)
					throw new ExifLibException("Malformed Exif data");

				// We're now into the TIFF format
				_tiffHeaderStart = _stream.Position;

				// What byte align will be used for the TIFF part of the document? II for Intel, MM for Motorola
				_isLittleEndian = ReadString(2) == "II";

				// Next 2 bytes are always the same.
				if (ReadUShort() != 0x002A)
					throw new ExifLibException("Error in TIFF data");

				// Get the offset to the IFD (image file directory)
				var ifdOffset = ReadUint();

				// Note that this offset is from the first byte of the TIFF header. Jump to the IFD.
				_stream.Position = ifdOffset + _tiffHeaderStart;

				// Catalogue this first IFD (there will be another IFD)
				_ifd0Catalogue = new Dictionary<ushort, long>();
				CatalogueIFD(ref _ifd0Catalogue);

				// The address to the IFD1 (the thumbnail IFD) is located immediately after the main IFD
				_ifd1Offset = ReadUint();

				// There's more data stored in the subifd, the offset to which is found in tag 0x8769.
				// As with all TIFF offsets, it will be relative to the first byte of the TIFF header.
				uint offset;
				if (!GetTagValue(_ifd0Catalogue, 0x8769, out offset))

View on GitHub (pinned to 4782bbd9ad)