FA-79006 / Image orientation metadata / Open access
HEIF irot is read as clockwise · case 01
HEIC photos stored with a quarter-turn irot display rotated the opposite way from other viewers.
ROOT CAUSE
irot counts anticlockwise quarter turns but is used directly as a clockwise count.
VERIFIED REPAIR
Convert anticlockwise turns to clockwise with (-irot) mod 4.
Unsuccessful approach: Adding a half turn fixes quarter turns only by accident and breaks irot 0 and 2.
Case contract
Resolve the displayed orientation tag from metadata sources. For HEIF, the container transforms are authoritative and EXIF/XMP are ignored: irot is anticlockwise quarter turns (default 0) applied first, then imir mirrors about the vertical axis (0, left-right) or the horizontal axis (1, top-bottom); the result is mapped to a tag through (k clockwise quarter turns after m mirrors) = {(0,0):1, (0,1):2, (2,0):3, (2,1):4, (3,1):5, (1,0):6, (1,1):7, (3,0):8}. For other containers a valid integer EXIF value 1..8 wins; otherwise an XMP string that is a single digit 1..8 after trimming whitespace; otherwise 1.
Why this case matters
Camera, phone and scanner images carry an orientation hint separately from the stored pixels; galleries, thumbnailers, editors and upload pipelines must interpret it consistently or photos appear sideways, mirrored or doubly rotated.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(meta):
from_km = {(0, 0): 1, (0, 1): 2, (2, 0): 3, (2, 1): 4, (3, 1): 5, (1, 0): 6, (1, 1): 7, (3, 0): 8}
c = meta.get('container')
if c == 'heif':
rot = meta.get('irot')
mir = meta.get('imir')
rot = 0 if rot is None else rot % 4
if mir is None:
return from_km[(rot, 0)]
if mir == 0:
return from_km[(rot, 1)]
return from_km[((rot + 2) % 4, 1)]
e = meta.get('exif')
if isinstance(e, int) and not isinstance(e, bool) and 1 <= e <= 8:
return e
x = meta.get('xmp')
if isinstance(x, str):
s = x.strip()
if s in ('1', '2', '3', '4', '5', '6', '7', '8'):
return int(s)
return 1
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'container': 'heif', 'xmp': '\t5', 'irot': 3}, 6], [{'container': 'heif', 'exif': 2, 'xmp': '6'}, 1], [{'container': 'png'}, 1], [{'container': 'jpeg', 'xmp': '2'}, 2], [{'container': 'tiff'}, 1], [{'container': 'tiff', 'exif': True, 'xmp': '7 '}, 7], [{'container': 'tiff', 'exif': True}, 1], [{'container': 'heif', 'xmp': '3\n', 'irot': 3}, 6]], [[{'container': 'heif', 'exif': 6, 'irot': 1}, 8], [{'container': 'heif', 'irot': 0}, 1], [{'container': 'png', 'xmp': '3\n'}, 3], [{'container': 'jpeg', 'exif': 0, 'xmp': '\t5'}, 5], [{'container': 'jpeg', 'exif': 0}, 1], [{'container': 'jpeg', 'xmp': '3\n'}, 3], [{'container': 'heif', 'exif': 5, 'xmp': ' 8', 'imir': 0}, 2], [{'container': 'heif', 'exif': 6, 'xmp': ' 8', 'irot': 3}, 6]], [[{'container': 'heif', 'exif': 2, 'xmp': ' 8', 'irot': 1}, 8], [{'container': 'heif', 'exif': 1, 'xmp': 'x'}, 1], [{'container': 'jpeg', 'xmp': '7 '}, 7], [{'container': 'tiff'}, 1], [{'container': 'jpeg'}, 1], [{'container': 'jpeg', 'exif': 0}, 1], [{'container': 'jpeg', 'exif': 9, 'xmp': ' 8'}, 8], [{'container': 'heif', 'exif': 7, 'xmp': '\t5', 'irot': 3}, 6]], [[{'container': 'heif', 'irot': 1}, 8], [{'container': 'heif', 'exif': True, 'irot': 0}, 1], [{'container': 'jpeg', 'exif': 1}, 1], [{'container': 'jpeg', 'xmp': '7 '}, 7], [{'container': 'tiff', 'exif': 5}, 5], [{'container': 'tiff', 'exif': 3, 'xmp': '3\n'}, 3], [{'container': 'tiff', 'exif': 7}, 7], [{'container': 'heif', 'xmp': 'x', 'irot': 1}, 8]], [[{'container': 'heif', 'irot': 3}, 6], [{'container': 'heif', 'exif': 7, 'xmp': ' 8', 'irot': 0}, 1], [{'container': 'png', 'exif': 7}, 7], [{'container': 'jpeg', 'exif': 7}, 7], [{'container': 'jpeg', 'exif': 2}, 2], [{'container': 'jpeg'}, 1], [{'container': 'jpeg', 'exif': 5, 'xmp': '6'}, 5], [{'container': 'heif', 'xmp': '7 ', 'irot': 3}, 6]]]
labels = ["regression: irot rotation direction", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: irot rotation direction 0 | 8 | 6 | Failed |
| repair trap 1 | 1 | 1 | Passed |
| combined fault 2 | 1 | 1 | Passed |
| control 3 | 2 | 2 | Passed |
| control 4 | 1 | 1 | Passed |
| boundary 5 | 7 | 7 | Passed |
| boundary 6 | 1 | 1 | Passed |
| control 7 | 8 | 6 | Failed |
SHA-256 / 64621d1881135e71a4c6b8df2920f67df6fa2e88b13a3f0b8701d7d7470190c4
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(meta):
from_km = {(0, 0): 1, (0, 1): 2, (2, 0): 3, (2, 1): 4, (3, 1): 5, (1, 0): 6, (1, 1): 7, (3, 0): 8}
c = meta.get('container')
if c == 'heif':
rot = meta.get('irot')
mir = meta.get('imir')
rot = 0 if rot is None else rot % 4
if mir is None:
return from_km[((rot + 2) % 4, 0)]
if mir == 0:
return from_km[(rot, 1)]
return from_km[((rot + 2) % 4, 1)]
e = meta.get('exif')
if isinstance(e, int) and not isinstance(e, bool) and 1 <= e <= 8:
return e
x = meta.get('xmp')
if isinstance(x, str):
s = x.strip()
if s in ('1', '2', '3', '4', '5', '6', '7', '8'):
return int(s)
return 1
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'container': 'heif', 'xmp': '\t5', 'irot': 3}, 6], [{'container': 'heif', 'exif': 2, 'xmp': '6'}, 1], [{'container': 'png'}, 1], [{'container': 'jpeg', 'xmp': '2'}, 2], [{'container': 'tiff'}, 1], [{'container': 'tiff', 'exif': True, 'xmp': '7 '}, 7], [{'container': 'tiff', 'exif': True}, 1], [{'container': 'heif', 'xmp': '3\n', 'irot': 3}, 6]], [[{'container': 'heif', 'exif': 6, 'irot': 1}, 8], [{'container': 'heif', 'irot': 0}, 1], [{'container': 'png', 'xmp': '3\n'}, 3], [{'container': 'jpeg', 'exif': 0, 'xmp': '\t5'}, 5], [{'container': 'jpeg', 'exif': 0}, 1], [{'container': 'jpeg', 'xmp': '3\n'}, 3], [{'container': 'heif', 'exif': 5, 'xmp': ' 8', 'imir': 0}, 2], [{'container': 'heif', 'exif': 6, 'xmp': ' 8', 'irot': 3}, 6]], [[{'container': 'heif', 'exif': 2, 'xmp': ' 8', 'irot': 1}, 8], [{'container': 'heif', 'exif': 1, 'xmp': 'x'}, 1], [{'container': 'jpeg', 'xmp': '7 '}, 7], [{'container': 'tiff'}, 1], [{'container': 'jpeg'}, 1], [{'container': 'jpeg', 'exif': 0}, 1], [{'container': 'jpeg', 'exif': 9, 'xmp': ' 8'}, 8], [{'container': 'heif', 'exif': 7, 'xmp': '\t5', 'irot': 3}, 6]], [[{'container': 'heif', 'irot': 1}, 8], [{'container': 'heif', 'exif': True, 'irot': 0}, 1], [{'container': 'jpeg', 'exif': 1}, 1], [{'container': 'jpeg', 'xmp': '7 '}, 7], [{'container': 'tiff', 'exif': 5}, 5], [{'container': 'tiff', 'exif': 3, 'xmp': '3\n'}, 3], [{'container': 'tiff', 'exif': 7}, 7], [{'container': 'heif', 'xmp': 'x', 'irot': 1}, 8]], [[{'container': 'heif', 'irot': 3}, 6], [{'container': 'heif', 'exif': 7, 'xmp': ' 8', 'irot': 0}, 1], [{'container': 'png', 'exif': 7}, 7], [{'container': 'jpeg', 'exif': 7}, 7], [{'container': 'jpeg', 'exif': 2}, 2], [{'container': 'jpeg'}, 1], [{'container': 'jpeg', 'exif': 5, 'xmp': '6'}, 5], [{'container': 'heif', 'xmp': '7 ', 'irot': 3}, 6]]]
labels = ["regression: irot rotation direction", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: irot rotation direction 0 | 6 | 6 | Passed |
| repair trap 1 | 3 | 1 | Failed |
| combined fault 2 | 1 | 1 | Passed |
| control 3 | 2 | 2 | Passed |
| control 4 | 1 | 1 | Passed |
| boundary 5 | 7 | 7 | Passed |
| boundary 6 | 1 | 1 | Passed |
| control 7 | 6 | 6 | Passed |
SHA-256 / 8bf4a6670de006fcf9bdb0cbdda5deda5ed94ad67042764ca5124128dfe61f2d
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
N = 1
observations = []
def solve(meta):
from_km = {(0, 0): 1, (0, 1): 2, (2, 0): 3, (2, 1): 4, (3, 1): 5, (1, 0): 6, (1, 1): 7, (3, 0): 8}
c = meta.get('container')
if c == 'heif':
rot = meta.get('irot')
mir = meta.get('imir')
rot = 0 if rot is None else rot % 4
if mir is None:
return from_km[((-rot) % 4, 0)]
if mir == 0:
return from_km[(rot, 1)]
return from_km[((rot + 2) % 4, 1)]
e = meta.get('exif')
if isinstance(e, int) and not isinstance(e, bool) and 1 <= e <= 8:
return e
x = meta.get('xmp')
if isinstance(x, str):
s = x.strip()
if s in ('1', '2', '3', '4', '5', '6', '7', '8'):
return int(s)
return 1
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[[{'container': 'heif', 'xmp': '\t5', 'irot': 3}, 6], [{'container': 'heif', 'exif': 2, 'xmp': '6'}, 1], [{'container': 'png'}, 1], [{'container': 'jpeg', 'xmp': '2'}, 2], [{'container': 'tiff'}, 1], [{'container': 'tiff', 'exif': True, 'xmp': '7 '}, 7], [{'container': 'tiff', 'exif': True}, 1], [{'container': 'heif', 'xmp': '3\n', 'irot': 3}, 6]], [[{'container': 'heif', 'exif': 6, 'irot': 1}, 8], [{'container': 'heif', 'irot': 0}, 1], [{'container': 'png', 'xmp': '3\n'}, 3], [{'container': 'jpeg', 'exif': 0, 'xmp': '\t5'}, 5], [{'container': 'jpeg', 'exif': 0}, 1], [{'container': 'jpeg', 'xmp': '3\n'}, 3], [{'container': 'heif', 'exif': 5, 'xmp': ' 8', 'imir': 0}, 2], [{'container': 'heif', 'exif': 6, 'xmp': ' 8', 'irot': 3}, 6]], [[{'container': 'heif', 'exif': 2, 'xmp': ' 8', 'irot': 1}, 8], [{'container': 'heif', 'exif': 1, 'xmp': 'x'}, 1], [{'container': 'jpeg', 'xmp': '7 '}, 7], [{'container': 'tiff'}, 1], [{'container': 'jpeg'}, 1], [{'container': 'jpeg', 'exif': 0}, 1], [{'container': 'jpeg', 'exif': 9, 'xmp': ' 8'}, 8], [{'container': 'heif', 'exif': 7, 'xmp': '\t5', 'irot': 3}, 6]], [[{'container': 'heif', 'irot': 1}, 8], [{'container': 'heif', 'exif': True, 'irot': 0}, 1], [{'container': 'jpeg', 'exif': 1}, 1], [{'container': 'jpeg', 'xmp': '7 '}, 7], [{'container': 'tiff', 'exif': 5}, 5], [{'container': 'tiff', 'exif': 3, 'xmp': '3\n'}, 3], [{'container': 'tiff', 'exif': 7}, 7], [{'container': 'heif', 'xmp': 'x', 'irot': 1}, 8]], [[{'container': 'heif', 'irot': 3}, 6], [{'container': 'heif', 'exif': 7, 'xmp': ' 8', 'irot': 0}, 1], [{'container': 'png', 'exif': 7}, 7], [{'container': 'jpeg', 'exif': 7}, 7], [{'container': 'jpeg', 'exif': 2}, 2], [{'container': 'jpeg'}, 1], [{'container': 'jpeg', 'exif': 5, 'xmp': '6'}, 5], [{'container': 'heif', 'xmp': '7 ', 'irot': 3}, 6]]]
labels = ["regression: irot rotation direction", "repair trap", "combined fault", "control", "control", "boundary", "boundary", "control"]
for i, (args, expected) in enumerate(fixtures[N-1]):
check("%s %d" % (labels[i % len(labels)], i), solve(args), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| regression: irot rotation direction 0 | 6 | 6 | Passed |
| repair trap 1 | 1 | 1 | Passed |
| combined fault 2 | 1 | 1 | Passed |
| control 3 | 2 | 2 | Passed |
| control 4 | 1 | 1 | Passed |
| boundary 5 | 7 | 7 | Passed |
| boundary 6 | 1 | 1 | Passed |
| control 7 | 6 | 6 | Passed |
SHA-256 / 7ca1dcb3353873e5197d43c330fa637ea048b0de6ec2408f79c28418b3a393aa
Verification & scope
A deterministic bounded teaching model with a stipulated contract; it makes no claim of conformance to any published specification. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:49:40.514000+00:00.
Case digest / 6d58b5e9ae762cf91044349c978973796ce39c2b06abda050d4000a389132a5b