wmjordan/PDFPatcher · warning · ExifLibException
Could not find Exif data block
Error message
Could not find Exif data block
What it means
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.
Source
Thrown at App/Processor/Imaging/JpgHelper.cs:395
private void ReadToExifStart() {
// The file has a number of blocks (Exif/JFIF), each of which
// has a tag number followed by a length. We scan the document until the required tag (0xFFE1)
// is found. All tags start with FF, so a non FF tag indicates an error.
// Get the next tag.
byte markerStart;
byte markerNumber = 0;
while (((markerStart = _reader.ReadByte()) == 0xFF) && (markerNumber = _reader.ReadByte()) != 0xE1) {
// Get the length of the data.
ushort dataLength = ReadUShort();
// Jump to the end of the data (note that the size field includes its own size)!
_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");
View on GitHub (pinned to 4782bbd9ad)
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.
Example fix
// before
ReadToExifStart(); // throws if no APP1
CreateTagIndex();
// after
try { ReadToExifStart(); CreateTagIndex(); }
catch (ExifLibException) {
// JPEG has no Exif block; return empty metadata
_ifd0Catalogue = new Dictionary<ushort, long>();
} Defensive patterns
Strategy: try-catch
Validate before calling
// Cannot cheaply pre-validate marker presence without scanning; // wrap the call instead.
Try / catch
try { ReadToExifStart(); CreateTagIndex(); }
catch (ExifLibException) { _ifd0Catalogue = new Dictionary<ushort, long>(); } Prevention
- Treat 'no Exif' as expected; do not let it abort processing.
- Skip Exif extraction for known non-photographic JPEGs.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Exif data not found
- 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/0e5fd655bdd53d6a.
Report an issue: GitHub.