FAILURE MAP
← Case archive

FA-81386 / MIDI event timing / Open access

Standard MIDI File header chunk reader: negative frame rate masked instead of negated · case 01

Every SMPTE-timed file is rejected: 0xE8 (-24) is read as 104 frames per second.

Verified by executionVariant 1 · 8 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The frame-rate byte has its sign bit masked off rather than being interpreted as a negative two's-complement value.

THE FAILURE

The frame-rate byte has its sign bit masked off rather than being interpreted as a negative two's-complement value.

Unsuccessful approach: Subtracting from 255 is a ones'-complement negation and yields 23, 24, 28 and 29 instead of 24, 25, 29 and 30.

Case contract

Input the bytes of a header chunk: "MThd", a 32-bit big-endian length (>= 6; extra bytes ignored but must be present), 16-bit format (0, 1, 2), 16-bit track count (nonzero; exactly 1 for format 0) and 16-bit division. If bit 15 of division is set, the high byte is a negative two's-complement frame rate (24, 25, 29, 30) and the low byte ticks per frame; otherwise division is ticks per quarter note (nonzero). Return a dict or None.

Why this case matters

MIDI sequencers, file readers and synth drivers depend on exact event ordering and tick/time arithmetic.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    if not isinstance(x, list) or len(x) < 14 or x[:4] != [77, 84, 104, 100]:
        return None
    length = (x[4] << 24) | (x[5] << 16) | (x[6] << 8) | x[7]
    if length < 6 or len(x) < 8 + length:
        return None
    fmt = (x[8] << 8) | x[9]
    ntrks = (x[10] << 8) | x[11]
    division = (x[12] << 8) | x[13]
    if fmt not in (0, 1, 2) or ntrks == 0 or (fmt == 0 and ntrks != 1):
        return None
    if division & 0x8000:
        fps = x[12] & 0x7F
        if fps not in (24, 25, 29, 30):
            return None
        return {'format': fmt, 'tracks': ntrks, 'fps': fps, 'ticks_per_frame': x[13]}
    if division == 0:
        return None
    return {'format': fmt, 'tracks': ntrks, 'ppq': division}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 2, 1, 224], {'format': 1, 'tracks': 2, 'ppq': 480}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 0, 0, 1, 0, 96], {'format': 0, 'tracks': 1, 'ppq': 96}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 0, 0, 2, 0, 96], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 3, 231, 40], {'format': 1, 'tracks': 3, 'fps': 25, 'ticks_per_frame': 40}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 227, 4], {'format': 1, 'tracks': 1, 'fps': 29, 'ticks_per_frame': 4}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 226, 100], {'format': 1, 'tracks': 1, 'fps': 30, 'ticks_per_frame': 100}), ([77, 84, 104, 100, 0, 0, 0, 8, 0, 1, 0, 2, 1, 224, 0, 0], {'format': 1, 'tracks': 2, 'ppq': 480}), ([77, 84, 104, 100, 0, 0, 0, 8, 0, 1, 0, 2, 1, 224], None)], [([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 232, 80], {'format': 1, 'tracks': 1, 'fps': 24, 'ticks_per_frame': 80}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 226, 100], {'format': 1, 'tracks': 1, 'fps': 30, 'ticks_per_frame': 100}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 230, 4], None), ([77, 84, 104, 100, 0, 0, 0, 8, 0, 1, 0, 2, 1, 224, 0, 0], {'format': 1, 'tracks': 2, 'ppq': 480}), ([77, 84, 104, 100, 0, 0, 0, 8, 0, 1, 0, 2, 1, 224], None), ([77, 84, 104, 100, 0, 0, 0, 5, 0, 1, 0, 2, 1, 224], None), ([77, 84, 104, 100, 0, 1, 0, 6, 0, 1, 0, 2, 1, 224], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 3, 0, 2, 1, 224], None)], [([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 3, 231, 40], {'format': 1, 'tracks': 3, 'fps': 25, 'ticks_per_frame': 40}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 227, 4], {'format': 1, 'tracks': 1, 'fps': 29, 'ticks_per_frame': 4}), ([77, 84, 104, 100, 0, 1, 0, 6, 0, 1, 0, 2, 1, 224], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 3, 0, 2, 1, 224], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 0, 1, 224], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 2, 0, 0], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 2, 0, 5, 0, 120], {'format': 2, 'tracks': 5, 'ppq': 120}), ([77, 84, 105, 100, 0, 0, 0, 6, 0, 1, 0, 2, 1, 224], None)], [([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 232, 80], {'format': 1, 'tracks': 1, 'fps': 24, 'ticks_per_frame': 80}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 226, 100], {'format': 1, 'tracks': 1, 'fps': 30, 'ticks_per_frame': 100}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 2, 0, 0], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 2, 0, 5, 0, 120], {'format': 2, 'tracks': 5, 'ppq': 120}), ([77, 84, 105, 100, 0, 0, 0, 6, 0, 1, 0, 2, 1, 224], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1], None), ([77, 84, 104, 100, 0, 0, 0, 7, 0, 1, 0, 2, 1, 224, 9], {'format': 1, 'tracks': 2, 'ppq': 480}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 2, 128, 0], None)], [([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 3, 231, 40], {'format': 1, 'tracks': 3, 'fps': 25, 'ticks_per_frame': 40}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 232, 80], {'format': 1, 'tracks': 1, 'fps': 24, 'ticks_per_frame': 80}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 227, 4], {'format': 1, 'tracks': 1, 'fps': 29, 'ticks_per_frame': 4}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 230, 4], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1], None), ([77, 84, 104, 100, 0, 0, 0, 7, 0, 1, 0, 2, 1, 224, 9], {'format': 1, 'tracks': 2, 'ppq': 480}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 2, 128, 0], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 0, 0, 1, 127, 255], {'format': 0, 'tracks': 1, 'ppq': 32767})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % 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 fixtureActualExpectedOutcome
oracle 0{'format': 1, 'ppq': 480, 'tracks': 2}{'format': 1, 'ppq': 480, 'tracks': 2}Passed
oracle 1{'format': 0, 'ppq': 96, 'tracks': 1}{'format': 0, 'ppq': 96, 'tracks': 1}Passed
oracle 2NoneNonePassed
oracle 3None{'format': 1, 'fps': 25, 'ticks_per_frame': 40, 'tracks': 3}Failed
oracle 4None{'format': 1, 'fps': 29, 'ticks_per_frame': 4, 'tracks': 1}Failed
oracle 5None{'format': 1, 'fps': 30, 'ticks_per_frame': 100, 'tracks': 1}Failed
oracle 6{'format': 1, 'ppq': 480, 'tracks': 2}{'format': 1, 'ppq': 480, 'tracks': 2}Passed
oracle 7NoneNonePassed

SHA-256 / 343cda1bd999fa944446fd13ff0d976e8abc2ef643c666702e65d843ad5d4d13

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    if not isinstance(x, list) or len(x) < 14 or x[:4] != [77, 84, 104, 100]:
        return None
    length = (x[4] << 24) | (x[5] << 16) | (x[6] << 8) | x[7]
    if length < 6 or len(x) < 8 + length:
        return None
    fmt = (x[8] << 8) | x[9]
    ntrks = (x[10] << 8) | x[11]
    division = (x[12] << 8) | x[13]
    if fmt not in (0, 1, 2) or ntrks == 0 or (fmt == 0 and ntrks != 1):
        return None
    if division & 0x8000:
        fps = 255 - x[12]
        if fps not in (24, 25, 29, 30):
            return None
        return {'format': fmt, 'tracks': ntrks, 'fps': fps, 'ticks_per_frame': x[13]}
    if division == 0:
        return None
    return {'format': fmt, 'tracks': ntrks, 'ppq': division}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 2, 1, 224], {'format': 1, 'tracks': 2, 'ppq': 480}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 0, 0, 1, 0, 96], {'format': 0, 'tracks': 1, 'ppq': 96}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 0, 0, 2, 0, 96], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 3, 231, 40], {'format': 1, 'tracks': 3, 'fps': 25, 'ticks_per_frame': 40}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 227, 4], {'format': 1, 'tracks': 1, 'fps': 29, 'ticks_per_frame': 4}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 226, 100], {'format': 1, 'tracks': 1, 'fps': 30, 'ticks_per_frame': 100}), ([77, 84, 104, 100, 0, 0, 0, 8, 0, 1, 0, 2, 1, 224, 0, 0], {'format': 1, 'tracks': 2, 'ppq': 480}), ([77, 84, 104, 100, 0, 0, 0, 8, 0, 1, 0, 2, 1, 224], None)], [([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 232, 80], {'format': 1, 'tracks': 1, 'fps': 24, 'ticks_per_frame': 80}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 226, 100], {'format': 1, 'tracks': 1, 'fps': 30, 'ticks_per_frame': 100}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 230, 4], None), ([77, 84, 104, 100, 0, 0, 0, 8, 0, 1, 0, 2, 1, 224, 0, 0], {'format': 1, 'tracks': 2, 'ppq': 480}), ([77, 84, 104, 100, 0, 0, 0, 8, 0, 1, 0, 2, 1, 224], None), ([77, 84, 104, 100, 0, 0, 0, 5, 0, 1, 0, 2, 1, 224], None), ([77, 84, 104, 100, 0, 1, 0, 6, 0, 1, 0, 2, 1, 224], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 3, 0, 2, 1, 224], None)], [([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 3, 231, 40], {'format': 1, 'tracks': 3, 'fps': 25, 'ticks_per_frame': 40}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 227, 4], {'format': 1, 'tracks': 1, 'fps': 29, 'ticks_per_frame': 4}), ([77, 84, 104, 100, 0, 1, 0, 6, 0, 1, 0, 2, 1, 224], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 3, 0, 2, 1, 224], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 0, 1, 224], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 2, 0, 0], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 2, 0, 5, 0, 120], {'format': 2, 'tracks': 5, 'ppq': 120}), ([77, 84, 105, 100, 0, 0, 0, 6, 0, 1, 0, 2, 1, 224], None)], [([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 232, 80], {'format': 1, 'tracks': 1, 'fps': 24, 'ticks_per_frame': 80}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 226, 100], {'format': 1, 'tracks': 1, 'fps': 30, 'ticks_per_frame': 100}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 2, 0, 0], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 2, 0, 5, 0, 120], {'format': 2, 'tracks': 5, 'ppq': 120}), ([77, 84, 105, 100, 0, 0, 0, 6, 0, 1, 0, 2, 1, 224], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1], None), ([77, 84, 104, 100, 0, 0, 0, 7, 0, 1, 0, 2, 1, 224, 9], {'format': 1, 'tracks': 2, 'ppq': 480}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 2, 128, 0], None)], [([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 3, 231, 40], {'format': 1, 'tracks': 3, 'fps': 25, 'ticks_per_frame': 40}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 232, 80], {'format': 1, 'tracks': 1, 'fps': 24, 'ticks_per_frame': 80}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 227, 4], {'format': 1, 'tracks': 1, 'fps': 29, 'ticks_per_frame': 4}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 1, 230, 4], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1], None), ([77, 84, 104, 100, 0, 0, 0, 7, 0, 1, 0, 2, 1, 224, 9], {'format': 1, 'tracks': 2, 'ppq': 480}), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 1, 0, 2, 128, 0], None), ([77, 84, 104, 100, 0, 0, 0, 6, 0, 0, 0, 1, 127, 255], {'format': 0, 'tracks': 1, 'ppq': 32767})]]
for i, (args, expected) in enumerate(fixtures[N-1]):
    check("oracle %d" % 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 fixtureActualExpectedOutcome
oracle 0{'format': 1, 'ppq': 480, 'tracks': 2}{'format': 1, 'ppq': 480, 'tracks': 2}Passed
oracle 1{'format': 0, 'ppq': 96, 'tracks': 1}{'format': 0, 'ppq': 96, 'tracks': 1}Passed
oracle 2NoneNonePassed
oracle 3{'format': 1, 'fps': 24, 'ticks_per_frame': 40, 'tracks': 3}{'format': 1, 'fps': 25, 'ticks_per_frame': 40, 'tracks': 3}Failed
oracle 4None{'format': 1, 'fps': 29, 'ticks_per_frame': 4, 'tracks': 1}Failed
oracle 5{'format': 1, 'fps': 29, 'ticks_per_frame': 100, 'tracks': 1}{'format': 1, 'fps': 30, 'ticks_per_frame': 100, 'tracks': 1}Failed
oracle 6{'format': 1, 'ppq': 480, 'tracks': 2}{'format': 1, 'ppq': 480, 'tracks': 2}Passed
oracle 7NoneNonePassed

SHA-256 / 67e3c4c1a2a3c79806274db5290562b70aec95c9f8f5161a08b138374aec8a3b

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 8 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

Verification & scope

A deterministic bounded teaching model with a stipulated toy contract; it is not a complete Standard MIDI File or MIDI 1.0/2.0 implementation. 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:50:02.497889+00:00.

Case digest / 39456993343925574a1c871ac85bc79d04c0b3acfc348b59bc23b5f4c6c27760