FAILURE MAP
← Case archive

FA-81371 / MIDI event timing / Open access

Variable-length quantity stream decoder: previous quantity bleeds into the next · case 01

In [0, 129, 0, 5] the second and third values absorb earlier bits instead of reading 128 and 5.

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

ROOT CAUSE

After a quantity completes, the byte counter is reset but the accumulator is not.

VERIFIED REPAIR

Restore the accumulator reset step so that it reads `values.append(cur) cur = 0 count = 0`.

Unsuccessful approach: Resetting the accumulator but not the byte counter makes the final truncation check reject every stream.

Case contract

Input a list of byte values. Decode consecutive variable-length quantities (7 data bits per byte, bit 7 = continuation, most significant first, at most 4 bytes each). Return the list of values; return None for a byte outside 0..255, a quantity whose fourth byte still has the continuation bit, or a truncated final quantity.

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):
        return None
    values = []
    cur = 0
    count = 0
    for b in x:
        if not isinstance(b, int) or b < 0 or b > 255:
            return None
        cur = (cur << 7) | (b & 0x7F)
        count += 1
        if b & 0x80:
            if count == 4:
                return None
            continue
        values.append(cur)
        count = 0
    if count:
        return None
    return values
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([0], [0]), ([192, 0], [8192]), ([255, 255, 255, 255, 127], None), ([129], None), ([0, 129, 0, 5], [0, 128, 5]), ([200, 1, 2], [9217, 2]), ([], []), ([256], None)], [([0], [0]), ([127], [127]), ([129, 0], [128]), ([129, 128, 0], [16384]), ([129, 0, 0, 129, 0], [128, 0, 128]), ([256], None), ([-1], None), ([131, 255, 127, 0], [65535, 0])], [([127], [127]), ([129, 0], [128]), ([192, 0], [8192]), ([129, 128, 0], [16384]), ([255, 255, 255, 127], [268435455]), ([0, 129, 0, 5], [0, 128, 5]), ([200, 1, 2], [9217, 2]), ([129, 0, 129, 0, 129, 0], [128, 128, 128])], [([192, 0], [8192]), ([129, 128, 0], [16384]), ([255, 255, 255, 127], [268435455]), ([0, 129, 0, 5], [0, 128, 5]), ([129, 0, 0, 129, 0], [128, 0, 128]), ([200, 1, 2], [9217, 2]), ([131, 255, 127, 0], [65535, 0]), ([1, 2, 3], [1, 2, 3])], [([129, 128, 0], [16384]), ([0, 129, 0, 5], [0, 128, 5]), ([129, 0, 0, 129, 0], [128, 0, 128]), ([200, 1, 2], [9217, 2]), ([131, 255, 127, 0], [65535, 0]), ([128, 128, 128, 0], [0]), ([128, 0], [0]), ([129, 0, 129, 0, 129, 0], [128, 128, 128])]]
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[0][0]Passed
oracle 1[8192][8192]Passed
oracle 2NoneNonePassed
oracle 3NoneNonePassed
oracle 4[0, 128, 16389][0, 128, 5]Failed
oracle 5[9217, 1179778][9217, 2]Failed
oracle 6[][]Passed
oracle 7NoneNonePassed

SHA-256 / 57cbdd50a8e0c77a02ab3cf88901aa62b67d89f92a11e9ec30b6f8d8ac52c2f1

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):
        return None
    values = []
    cur = 0
    count = 0
    for b in x:
        if not isinstance(b, int) or b < 0 or b > 255:
            return None
        cur = (cur << 7) | (b & 0x7F)
        count += 1
        if b & 0x80:
            if count == 4:
                return None
            continue
        values.append(cur)
        cur = 0
    if count:
        return None
    return values
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([0], [0]), ([192, 0], [8192]), ([255, 255, 255, 255, 127], None), ([129], None), ([0, 129, 0, 5], [0, 128, 5]), ([200, 1, 2], [9217, 2]), ([], []), ([256], None)], [([0], [0]), ([127], [127]), ([129, 0], [128]), ([129, 128, 0], [16384]), ([129, 0, 0, 129, 0], [128, 0, 128]), ([256], None), ([-1], None), ([131, 255, 127, 0], [65535, 0])], [([127], [127]), ([129, 0], [128]), ([192, 0], [8192]), ([129, 128, 0], [16384]), ([255, 255, 255, 127], [268435455]), ([0, 129, 0, 5], [0, 128, 5]), ([200, 1, 2], [9217, 2]), ([129, 0, 129, 0, 129, 0], [128, 128, 128])], [([192, 0], [8192]), ([129, 128, 0], [16384]), ([255, 255, 255, 127], [268435455]), ([0, 129, 0, 5], [0, 128, 5]), ([129, 0, 0, 129, 0], [128, 0, 128]), ([200, 1, 2], [9217, 2]), ([131, 255, 127, 0], [65535, 0]), ([1, 2, 3], [1, 2, 3])], [([129, 128, 0], [16384]), ([0, 129, 0, 5], [0, 128, 5]), ([129, 0, 0, 129, 0], [128, 0, 128]), ([200, 1, 2], [9217, 2]), ([131, 255, 127, 0], [65535, 0]), ([128, 128, 128, 0], [0]), ([128, 0], [0]), ([129, 0, 129, 0, 129, 0], [128, 128, 128])]]
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 0None[0]Failed
oracle 1None[8192]Failed
oracle 2NoneNonePassed
oracle 3NoneNonePassed
oracle 4None[0, 128, 5]Failed
oracle 5None[9217, 2]Failed
oracle 6[][]Passed
oracle 7NoneNonePassed

SHA-256 / 45a7d7acb7f9836a6a11bb0b634b7c0d53b95b95480472e3c1da6c69f8eec4c0

3 / The verified repair

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

N = 1
observations = []
def solve(x):
    if not isinstance(x, list):
        return None
    values = []
    cur = 0
    count = 0
    for b in x:
        if not isinstance(b, int) or b < 0 or b > 255:
            return None
        cur = (cur << 7) | (b & 0x7F)
        count += 1
        if b & 0x80:
            if count == 4:
                return None
            continue
        values.append(cur)
        cur = 0
        count = 0
    if count:
        return None
    return values
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[([0], [0]), ([192, 0], [8192]), ([255, 255, 255, 255, 127], None), ([129], None), ([0, 129, 0, 5], [0, 128, 5]), ([200, 1, 2], [9217, 2]), ([], []), ([256], None)], [([0], [0]), ([127], [127]), ([129, 0], [128]), ([129, 128, 0], [16384]), ([129, 0, 0, 129, 0], [128, 0, 128]), ([256], None), ([-1], None), ([131, 255, 127, 0], [65535, 0])], [([127], [127]), ([129, 0], [128]), ([192, 0], [8192]), ([129, 128, 0], [16384]), ([255, 255, 255, 127], [268435455]), ([0, 129, 0, 5], [0, 128, 5]), ([200, 1, 2], [9217, 2]), ([129, 0, 129, 0, 129, 0], [128, 128, 128])], [([192, 0], [8192]), ([129, 128, 0], [16384]), ([255, 255, 255, 127], [268435455]), ([0, 129, 0, 5], [0, 128, 5]), ([129, 0, 0, 129, 0], [128, 0, 128]), ([200, 1, 2], [9217, 2]), ([131, 255, 127, 0], [65535, 0]), ([1, 2, 3], [1, 2, 3])], [([129, 128, 0], [16384]), ([0, 129, 0, 5], [0, 128, 5]), ([129, 0, 0, 129, 0], [128, 0, 128]), ([200, 1, 2], [9217, 2]), ([131, 255, 127, 0], [65535, 0]), ([128, 128, 128, 0], [0]), ([128, 0], [0]), ([129, 0, 129, 0, 129, 0], [128, 128, 128])]]
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[0][0]Passed
oracle 1[8192][8192]Passed
oracle 2NoneNonePassed
oracle 3NoneNonePassed
oracle 4[0, 128, 5][0, 128, 5]Passed
oracle 5[9217, 2][9217, 2]Passed
oracle 6[][]Passed
oracle 7NoneNonePassed

SHA-256 / 08fcde08842f48cbbb559a4ce12a53219afa04e8fbc5201b77cf430434dc2fff

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

Case digest / a66acb75a39dde6477b9d91183b143a946d8f105fe672f3d8c84e83d94191ad8