{"record":{"id":"f472af069b50f364","repo":"siyuan-note/siyuan","slug":"avif-invalid-exif-byte-order-marker","errorCode":null,"errorMessage":"avif: invalid exif byte order marker","messagePattern":"avif: invalid exif byte order marker","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/heif/internal/h265heic/exif.go","lineNumber":282,"sourceCode":"\tif den == 0 {\n\t\treturn 0\n\t}\n\n\treturn float64(num) / float64(den)\n}\n\nfunc parseExifData(data []byte, exif *Exif) error {\n\tif len(data) < 8 {\n\t\treturn errors.New(\"avif: exif data too short\")\n\t}\n\n\tr := &exifReader{data: data}\n\tswitch {\n\tcase data[0] == 'I' && data[1] == 'I':\n\t\tr.littleEndian = true\n\tcase data[0] == 'M' && data[1] == 'M':\n\tdefault:\n\t\treturn errors.New(\"avif: invalid exif byte order marker\")\n\t}\n\n\tif r.uint16(2) != 42 {\n\t\treturn errors.New(\"avif: invalid exif magic number\")\n\t}\n\n\tifdOffset := r.uint32(4)\n\tif ifdOffset < 8 || int(ifdOffset) >= len(data) {\n\t\treturn errors.New(\"avif: invalid exif ifd offset\")\n\t}\n\n\texifIFDOffset, gpsIFDOffset := parseIFD(r, int(ifdOffset), exif)\n\tif exifIFDOffset > 0 {\n\t\tparseExifSubIFD(r, exifIFDOffset, exif)\n\t}\n\tif gpsIFDOffset > 0 {\n\t\tparseGPSSubIFD(r, gpsIFDOffset, exif)\n\t}","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/heif/internal/h265heic/exif.go#L264-L300","documentation":"The EXIF TIFF header's first two bytes must be the byte-order marker 'II' (little-endian) or 'MM' (big-endian). parseExifData found other bytes, meaning the payload is not a TIFF-style EXIF block. This usually indicates the wrong bytes were handed to the EXIF parser (offset error, or the payload is XMP/raw data instead of EXIF).","triggerScenarios":"DecodeExif on a HEIF whose Exif item payload does not begin with 'II' or 'MM' — e.g. the parser was pointed at the item data including an offset skip it did not expect, or the item actually contains XMP or vendor blobs.","commonSituations":"Files where the EXIF item has a 4-byte offset prefix that was not skipped; cameras writing non-standard metadata items; mixing up XMP and Exif item indices when extracting from the meta box.","solutions":["Inspect the first bytes of the payload; if it is XML it is XMP, not EXIF — parse with an XMP reader","Check whether the container prepends an offset/length header to the EXIF item that must be skipped","Treat the file as having no readable EXIF and fall back to defaults (orientation 1)","Re-export the image from the original camera/software to regenerate standards-compliant EXIF"],"exampleFix":"// before\npayload := itemData(exifItem) // includes 4-byte offset prefix\nexif, err := parse(payload)   // -> invalid byte order marker\n// after\npayload := itemData(exifItem)\nif len(payload) > 4 && payload[0] != 'I' && payload[0] != 'M' {\n\tpayload = payload[4:] // skip TIFF-header offset prefix\n}\nexif, err := parse(payload)","handlingStrategy":"validation","validationCode":"func hasTIFFByteOrderMark(data []byte) bool {\n\treturn len(data) >= 2 && ((data[0] == 'I' && data[1] == 'I') || (data[0] == 'M' && data[1] == 'M'))\n}","typeGuard":"func isExifPayload(b []byte) bool {\n\treturn hasTIFFByteOrderMark(b)\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"invalid exif byte order marker\") {\n\t// payload is likely XMP or offset-prefixed; skip EXIF gracefully\n\treturn nil, nil\n}","preventionTips":["Confirm the item you extract is the Exif item, not XMP or another metadata item","Skip any offset-prefix bytes the container adds before the TIFF header","Peek at the first two bytes before parsing EXIF","Handle EXIF absence as the normal case for stripped/edited images"],"tags":["exif","metadata","byte-order-marker","tiff"],"backgroundTag":"invalid-argument-format","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}