wmjordan/PDFPatcher · warning · ExifLibException
Exif data not found
Error message
Exif data not found
What it means
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).
Source
Thrown at App/Processor/Imaging/JpgHelper.cs:408
_stream.Seek(dataLength - 2, SeekOrigin.Current);
}
// It's only success if we found the 0xFFE1 marker
if (markerStart != 0xFF || markerNumber != 0xE1)
throw new ExifLibException("Could not find Exif data block");
}
/// <summary>
/// Reads through the Exif data and builds an index of all Exif tags in the document
/// </summary>
/// <returns></returns>
private void CreateTagIndex() {
// The next 4 bytes are the size of the Exif data.
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();
View on GitHub (pinned to 4782bbd9ad)
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.
Example fix
// before
if (ReadString(4) != "Exif")
throw new ExifLibException("Exif data not found");
// after
if (ReadString(4) != "Exif") {
// APP1 is present but is not Exif (likely XMP); return empty catalogue
_ifd0Catalogue = new Dictionary<ushort, long>();
return;
} Defensive patterns
Strategy: try-catch
Validate before calling
// Inspect APP1 payload head for 'Exif' before deep parsing.
Type guard
// APP1 is Exif only if payload starts with ASCII "Exif"
Try / catch
try { CreateTagIndex(); }
catch (ExifLibException) { _ifd0Catalogue = new Dictionary<ushort, long>(); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Could not find Exif data block
- File is not a valid JPEG
- Malformed Exif data
- Error in TIFF data
- “[]”筛选表达式前缺少节点轴及节点名称标识。
AI-assisted analysis of wmjordan/PDFPatcher@4782bbd9ad (2026-08-13).
Data as JSON: /api/errors/82294cb14fdc9525.
Report an issue: GitHub.