siyuan-note/siyuan · warning
avif: invalid exif magic number
Error message
avif: invalid exif magic number
What it means
After the byte-order marker, an EXIF TIFF header must contain the magic number 42 at offset 2. The parser read a different value, so the payload is not a valid EXIF/TIFF structure despite having plausible 'II'/'MM' markers. This confirms the payload is corrupt or not actually EXIF data.
Source
Thrown at kernel/heif/internal/h265heic/exif.go:286
return float64(num) / float64(den)
}
func parseExifData(data []byte, exif *Exif) error {
if len(data) < 8 {
return errors.New("avif: exif data too short")
}
r := &exifReader{data: data}
switch {
case data[0] == 'I' && data[1] == 'I':
r.littleEndian = true
case data[0] == 'M' && data[1] == 'M':
default:
return errors.New("avif: invalid exif byte order marker")
}
if r.uint16(2) != 42 {
return errors.New("avif: invalid exif magic number")
}
ifdOffset := r.uint32(4)
if ifdOffset < 8 || int(ifdOffset) >= len(data) {
return errors.New("avif: invalid exif ifd offset")
}
exifIFDOffset, gpsIFDOffset := parseIFD(r, int(ifdOffset), exif)
if exifIFDOffset > 0 {
parseExifSubIFD(r, exifIFDOffset, exif)
}
if gpsIFDOffset > 0 {
parseGPSSubIFD(r, gpsIFDOffset, exif)
}
return nil
}
View on GitHub (pinned to 8641553a1f)
Solutions
- Verify the Exif item's data extent points at the TIFF header start, not into the payload
- Dump the first 8 bytes and compare against the expected II\x2a\x00 or MM\x00\x2a header
- Treat EXIF as unavailable and continue rendering the image without orientation/GPS metadata
- Regenerate the file with a standards-compliant writer if it is your own tooling
Defensive patterns
Strategy: validation
Validate before calling
func looksLikeExifTIFF(data []byte) bool {
if len(data) < 4 {
return false
}
if data[0] == 'I' && data[1] == 'I' {
return binary.LittleEndian.Uint16(data[2:4]) == 42
}
if data[0] == 'M' && data[1] == 'M' {
return binary.BigEndian.Uint16(data[2:4]) == 42
}
return false
} Type guard
func isWellFormedTIFFHeader(b []byte) bool { return looksLikeExifTIFF(b) } Try / catch
if err != nil && strings.Contains(err.Error(), "invalid exif magic number") {
log.Warnf("EXIF payload is not a TIFF structure: %v", err)
return nil
} Prevention
- Validate the full 8-byte TIFF header (marker + magic 42) before IFD parsing
- Check item extents so slicing never starts mid-blob
- Treat metadata parse errors as non-fatal and continue with defaults
- Regenerate files with standards-compliant EXIF writers in your own pipelines
When it happens
Trigger: DecodeExif on a payload whose bytes 2-3 (per declared endianness) do not equal 42 — e.g. sliced into the middle of a larger blob, or a fabricated/fuzzed TIFF header.
Common situations: Off-by-N slicing of the Exif item; files produced by buggy metadata writers; binary blobs mislabeled as Exif items in the HEIF meta box.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- avif: exif data too short
- avif: invalid exif byte order marker
- avif: invalid exif ifd offset
- invalid bazaar index generation metadata
- OAuth authorization server metadata not found
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/d1738c017949d41a.
Report an issue: GitHub.