FAILURE MAP
← Case archive

FA-77861 / Subtitle cue timing / Open access

SRT timestamp parsing: surrounding whitespace · case 01

Every cue from a CRLF subtitle file fails to parse because its end timestamp carries a carriage return.

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

ROOT CAUSE

Surrounding whitespace is not removed, so a trailing CR makes the fraction non-numeric.

VERIFIED REPAIR

Strip whitespace on both sides of the timestamp before parsing.

Unsuccessful approach: Stripping only leading whitespace still leaves the trailing CR from Windows line endings.

Case contract

Parse an SRT timestamp HH:MM:SS,mmm to integer milliseconds. Hours have 2 or more digits, minutes and seconds are below 60, the fraction has 1 to 3 digits and is right-padded (",5" means 500 ms), "." is accepted as the separator, surrounding whitespace (including a CR from CRLF files) is ignored; invalid text returns None.

Why this case matters

Subtitle timing defects shift, hide or overlap captions that viewers depend on for comprehension and accessibility.

1 / The failure

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

N = 1
observations = []
def solve(s):
    s=s
    parts=s.replace('.',',').split(',')
    if len(parts)!=2: return None
    hms,frac=parts
    fields=hms.split(':')
    if len(fields)!=3: return None
    if not all(p.isdigit() for p in fields) or not frac.isdigit(): return None
    if len(frac)>3: return None
    h,mi,se=int(fields[0]),int(fields[1]),int(fields[2])
    if mi>=60 or se>=60: return None
    ms=int(frac.ljust(3,'0'))
    return h*3600000+mi*60000+se*1000+ms
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: surrounding whitespace', ['00:59:59,999\r'], 3599999), ('regression variant: surrounding whitespace', ['01:05:00,500\r'], 3900500), ('partial repair probe: surrounding whitespace', ['99:00:59,001 \r'], 356459001), ('partial repair variant: surrounding whitespace', ['100:59:42.001\r'], 363582001), ('boundary control', ['00:00:00,000'], 0), ('boundary control', ['00:60:00,000'], None), ('normal control', ['00:00:01,5'], 1500), ('normal control', ['100:00:00,000'], 360000000), ('normal control', ['00:61:00;5 \r'], None)], [('regression: surrounding whitespace', ['99:00:00.500\r'], 356400500), ('regression variant: surrounding whitespace', [' 00:05:00.5 '], 300500), ('partial repair probe: surrounding whitespace', ['01:30:01,500 \r'], 5401500), ('partial repair variant: surrounding whitespace', ['00:30:59,12 '], 1859120), ('boundary control', ['00:00:01,5'], 1500), ('boundary control', ['100:00:00,000'], 360000000), ('normal control', ['123:60:59,5'], None), ('normal control', [' 00:30:60,500'], None), ('normal control', ['00:00:60.1234 '], None)], [('regression: surrounding whitespace', ['99:00:59,001 \r'], 356459001), ('regression variant: surrounding whitespace', ['100:30:42,500\r'], 361842500), ('partial repair probe: surrounding whitespace', ['01:05:00,500\r'], 3900500), ('partial repair variant: surrounding whitespace', ['10:05:42,000 '], 36342000), ('boundary control', ['01:02:03.004'], 3723004), ('boundary control', ['00:00:00,000'], 0), ('normal control', ['123:60:42,999'], None), ('normal control', ['00:30:59;12'], None), ('normal control', ['00:00:60,1234\r'], None)], [('regression: surrounding whitespace', ['01:30:01,500 \r'], 5401500), ('regression variant: surrounding whitespace', ['123:05:01,001\t'], 443101001), ('partial repair probe: surrounding whitespace', [' 00:05:00.5 '], 300500), ('partial repair variant: surrounding whitespace', [' 123:59:42,50 '], 446382500), ('boundary control', ['00:60:00,000'], None), ('boundary control', ['00:00:01,5'], 1500), ('normal control', ['00:59:00.000'], 3540000), ('normal control', [' 00:61:42,000'], None), ('normal control', ['100:60:60,999 '], None)], [('regression: surrounding whitespace', [' 10:05:00.000'], 36300000), ('regression variant: surrounding whitespace', ['02:30:42,5\t'], 9042500), ('partial repair probe: surrounding whitespace', ['100:30:42,500\r'], 361842500), ('partial repair variant: surrounding whitespace', ['01:59:00.500\t'], 7140500), ('boundary control', ['100:00:00,000'], 360000000), ('boundary control', ['01:02:03.004'], 3723004), ('normal control', ['02:00:01,1234 \r'], None), ('normal control', [' 99:60:60, '], None), ('normal control', [' 100:59:61,50'], None)]]
for label, args, expected in fixtures[N-1]:
    check(label, 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
regression: surrounding whitespaceNone3599999Failed
regression variant: surrounding whitespaceNone3900500Failed
partial repair probe: surrounding whitespaceNone356459001Failed
partial repair variant: surrounding whitespaceNone363582001Failed
boundary control00Passed
boundary controlNoneNonePassed
normal control15001500Passed
normal control360000000360000000Passed
normal controlNoneNonePassed

SHA-256 / e323501653d4c0433f4d6d104f3a0d274433def157140e7a7bbd7cea45e4141f

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(s):
    s=s.lstrip()
    parts=s.replace('.',',').split(',')
    if len(parts)!=2: return None
    hms,frac=parts
    fields=hms.split(':')
    if len(fields)!=3: return None
    if not all(p.isdigit() for p in fields) or not frac.isdigit(): return None
    if len(frac)>3: return None
    h,mi,se=int(fields[0]),int(fields[1]),int(fields[2])
    if mi>=60 or se>=60: return None
    ms=int(frac.ljust(3,'0'))
    return h*3600000+mi*60000+se*1000+ms
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: surrounding whitespace', ['00:59:59,999\r'], 3599999), ('regression variant: surrounding whitespace', ['01:05:00,500\r'], 3900500), ('partial repair probe: surrounding whitespace', ['99:00:59,001 \r'], 356459001), ('partial repair variant: surrounding whitespace', ['100:59:42.001\r'], 363582001), ('boundary control', ['00:00:00,000'], 0), ('boundary control', ['00:60:00,000'], None), ('normal control', ['00:00:01,5'], 1500), ('normal control', ['100:00:00,000'], 360000000), ('normal control', ['00:61:00;5 \r'], None)], [('regression: surrounding whitespace', ['99:00:00.500\r'], 356400500), ('regression variant: surrounding whitespace', [' 00:05:00.5 '], 300500), ('partial repair probe: surrounding whitespace', ['01:30:01,500 \r'], 5401500), ('partial repair variant: surrounding whitespace', ['00:30:59,12 '], 1859120), ('boundary control', ['00:00:01,5'], 1500), ('boundary control', ['100:00:00,000'], 360000000), ('normal control', ['123:60:59,5'], None), ('normal control', [' 00:30:60,500'], None), ('normal control', ['00:00:60.1234 '], None)], [('regression: surrounding whitespace', ['99:00:59,001 \r'], 356459001), ('regression variant: surrounding whitespace', ['100:30:42,500\r'], 361842500), ('partial repair probe: surrounding whitespace', ['01:05:00,500\r'], 3900500), ('partial repair variant: surrounding whitespace', ['10:05:42,000 '], 36342000), ('boundary control', ['01:02:03.004'], 3723004), ('boundary control', ['00:00:00,000'], 0), ('normal control', ['123:60:42,999'], None), ('normal control', ['00:30:59;12'], None), ('normal control', ['00:00:60,1234\r'], None)], [('regression: surrounding whitespace', ['01:30:01,500 \r'], 5401500), ('regression variant: surrounding whitespace', ['123:05:01,001\t'], 443101001), ('partial repair probe: surrounding whitespace', [' 00:05:00.5 '], 300500), ('partial repair variant: surrounding whitespace', [' 123:59:42,50 '], 446382500), ('boundary control', ['00:60:00,000'], None), ('boundary control', ['00:00:01,5'], 1500), ('normal control', ['00:59:00.000'], 3540000), ('normal control', [' 00:61:42,000'], None), ('normal control', ['100:60:60,999 '], None)], [('regression: surrounding whitespace', [' 10:05:00.000'], 36300000), ('regression variant: surrounding whitespace', ['02:30:42,5\t'], 9042500), ('partial repair probe: surrounding whitespace', ['100:30:42,500\r'], 361842500), ('partial repair variant: surrounding whitespace', ['01:59:00.500\t'], 7140500), ('boundary control', ['100:00:00,000'], 360000000), ('boundary control', ['01:02:03.004'], 3723004), ('normal control', ['02:00:01,1234 \r'], None), ('normal control', [' 99:60:60, '], None), ('normal control', [' 100:59:61,50'], None)]]
for label, args, expected in fixtures[N-1]:
    check(label, 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
regression: surrounding whitespaceNone3599999Failed
regression variant: surrounding whitespaceNone3900500Failed
partial repair probe: surrounding whitespaceNone356459001Failed
partial repair variant: surrounding whitespaceNone363582001Failed
boundary control00Passed
boundary controlNoneNonePassed
normal control15001500Passed
normal control360000000360000000Passed
normal controlNoneNonePassed

SHA-256 / e07ebd6317c8994e43f6a183d30a569a3e138dfb7b57182af5c715743125ef17

3 / The verified repair

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

N = 1
observations = []
def solve(s):
    s=s.strip()
    parts=s.replace('.',',').split(',')
    if len(parts)!=2: return None
    hms,frac=parts
    fields=hms.split(':')
    if len(fields)!=3: return None
    if not all(p.isdigit() for p in fields) or not frac.isdigit(): return None
    if len(frac)>3: return None
    h,mi,se=int(fields[0]),int(fields[1]),int(fields[2])
    if mi>=60 or se>=60: return None
    ms=int(frac.ljust(3,'0'))
    return h*3600000+mi*60000+se*1000+ms
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('regression: surrounding whitespace', ['00:59:59,999\r'], 3599999), ('regression variant: surrounding whitespace', ['01:05:00,500\r'], 3900500), ('partial repair probe: surrounding whitespace', ['99:00:59,001 \r'], 356459001), ('partial repair variant: surrounding whitespace', ['100:59:42.001\r'], 363582001), ('boundary control', ['00:00:00,000'], 0), ('boundary control', ['00:60:00,000'], None), ('normal control', ['00:00:01,5'], 1500), ('normal control', ['100:00:00,000'], 360000000), ('normal control', ['00:61:00;5 \r'], None)], [('regression: surrounding whitespace', ['99:00:00.500\r'], 356400500), ('regression variant: surrounding whitespace', [' 00:05:00.5 '], 300500), ('partial repair probe: surrounding whitespace', ['01:30:01,500 \r'], 5401500), ('partial repair variant: surrounding whitespace', ['00:30:59,12 '], 1859120), ('boundary control', ['00:00:01,5'], 1500), ('boundary control', ['100:00:00,000'], 360000000), ('normal control', ['123:60:59,5'], None), ('normal control', [' 00:30:60,500'], None), ('normal control', ['00:00:60.1234 '], None)], [('regression: surrounding whitespace', ['99:00:59,001 \r'], 356459001), ('regression variant: surrounding whitespace', ['100:30:42,500\r'], 361842500), ('partial repair probe: surrounding whitespace', ['01:05:00,500\r'], 3900500), ('partial repair variant: surrounding whitespace', ['10:05:42,000 '], 36342000), ('boundary control', ['01:02:03.004'], 3723004), ('boundary control', ['00:00:00,000'], 0), ('normal control', ['123:60:42,999'], None), ('normal control', ['00:30:59;12'], None), ('normal control', ['00:00:60,1234\r'], None)], [('regression: surrounding whitespace', ['01:30:01,500 \r'], 5401500), ('regression variant: surrounding whitespace', ['123:05:01,001\t'], 443101001), ('partial repair probe: surrounding whitespace', [' 00:05:00.5 '], 300500), ('partial repair variant: surrounding whitespace', [' 123:59:42,50 '], 446382500), ('boundary control', ['00:60:00,000'], None), ('boundary control', ['00:00:01,5'], 1500), ('normal control', ['00:59:00.000'], 3540000), ('normal control', [' 00:61:42,000'], None), ('normal control', ['100:60:60,999 '], None)], [('regression: surrounding whitespace', [' 10:05:00.000'], 36300000), ('regression variant: surrounding whitespace', ['02:30:42,5\t'], 9042500), ('partial repair probe: surrounding whitespace', ['100:30:42,500\r'], 361842500), ('partial repair variant: surrounding whitespace', ['01:59:00.500\t'], 7140500), ('boundary control', ['100:00:00,000'], 360000000), ('boundary control', ['01:02:03.004'], 3723004), ('normal control', ['02:00:01,1234 \r'], None), ('normal control', [' 99:60:60, '], None), ('normal control', [' 100:59:61,50'], None)]]
for label, args, expected in fixtures[N-1]:
    check(label, 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
regression: surrounding whitespace35999993599999Passed
regression variant: surrounding whitespace39005003900500Passed
partial repair probe: surrounding whitespace356459001356459001Passed
partial repair variant: surrounding whitespace363582001363582001Passed
boundary control00Passed
boundary controlNoneNonePassed
normal control15001500Passed
normal control360000000360000000Passed
normal controlNoneNonePassed

SHA-256 / 350109be4e05fee1ab627ae0ef4b8eeffb81f83aabfed88f17961ad9ef3cd1ed

Verification & scope

A deterministic bounded teaching model with a stipulated toy contract; it does not claim conformance to any subtitle standard. 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:29.947808+00:00.

Case digest / cb4e4ae2798388ba5f123679c2a1873244c18e30107dd89b5881a47223ec0764