FAILURE MAP
← Case archive

FA-81391 / MIDI event timing / Open access

Standard MIDI File header chunk reader: multi-track format 0 accepted · case 01

A format 0 header declaring two tracks is accepted instead of rejected.

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

ROOT CAUSE

The single-track requirement of format 0 is not enforced.

THE FAILURE

The single-track requirement of format 0 is not enforced.

Unsuccessful approach: Checking for fewer than one track duplicates the zero-track check and still accepts two tracks.

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:
        return None
    if division & 0x8000:
        fps = 256 - 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, 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, 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, 6, 0, 0, 0, 2, 0, 96], 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, 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, 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, 0, 0, 6, 0, 0, 0, 2, 0, 96], None), ([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, 0, 1, 224], None)], [([77, 84, 104, 100, 0, 0, 0, 6, 0, 0, 0, 2, 0, 96], 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, 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, 0, 0, 2, 0, 96], 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], 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)]]
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 2{'format': 0, 'ppq': 96, 'tracks': 2}NoneFailed
oracle 3{'format': 1, 'fps': 25, 'ticks_per_frame': 40, 'tracks': 3}{'format': 1, 'fps': 25, 'ticks_per_frame': 40, 'tracks': 3}Passed
oracle 4{'format': 1, 'fps': 24, 'ticks_per_frame': 80, 'tracks': 1}{'format': 1, 'fps': 24, 'ticks_per_frame': 80, 'tracks': 1}Passed
oracle 5{'format': 1, 'fps': 29, 'ticks_per_frame': 4, 'tracks': 1}{'format': 1, 'fps': 29, 'ticks_per_frame': 4, 'tracks': 1}Passed
oracle 6{'format': 1, 'fps': 30, 'ticks_per_frame': 100, 'tracks': 1}{'format': 1, 'fps': 30, 'ticks_per_frame': 100, 'tracks': 1}Passed
oracle 7NoneNonePassed

SHA-256 / bca49fdec155d889a9b65e0322c51f2f496e62cc4a4cf72c3850919adb93a2e3

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 = 256 - 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, 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, 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, 6, 0, 0, 0, 2, 0, 96], 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, 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, 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, 0, 0, 6, 0, 0, 0, 2, 0, 96], None), ([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, 0, 1, 224], None)], [([77, 84, 104, 100, 0, 0, 0, 6, 0, 0, 0, 2, 0, 96], 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, 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, 0, 0, 2, 0, 96], 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], 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)]]
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 2{'format': 0, 'ppq': 96, 'tracks': 2}NoneFailed
oracle 3{'format': 1, 'fps': 25, 'ticks_per_frame': 40, 'tracks': 3}{'format': 1, 'fps': 25, 'ticks_per_frame': 40, 'tracks': 3}Passed
oracle 4{'format': 1, 'fps': 24, 'ticks_per_frame': 80, 'tracks': 1}{'format': 1, 'fps': 24, 'ticks_per_frame': 80, 'tracks': 1}Passed
oracle 5{'format': 1, 'fps': 29, 'ticks_per_frame': 4, 'tracks': 1}{'format': 1, 'fps': 29, 'ticks_per_frame': 4, 'tracks': 1}Passed
oracle 6{'format': 1, 'fps': 30, 'ticks_per_frame': 100, 'tracks': 1}{'format': 1, 'fps': 30, 'ticks_per_frame': 100, 'tracks': 1}Passed
oracle 7NoneNonePassed

SHA-256 / 9b8e2d2f6167302404f0b48f18fa483ac01172e3e597da5f4523482ac57589f3

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.503692+00:00.

Case digest / 7c087ce11e87efca3968b6172fe0cdb08015e2fdccf924dd74049ef5c1e5e9ad