FA-48806 / Delimited text / Open access
CSV row provenance reverses start and end positions · case 01
A structured table violates the declared record or column contract.
ROOT CAUSE
CSV row provenance reverses start and end positions.
VERIFIED REPAIR
Preserve the named invariant at the faulty decision: out.append([start,end,cells])
Unsuccessful approach: The alternate implementation still violates the same declared invariant: csv row provenance reverses start and end positions.
Case contract
Parse bounded valid CSV text using Python csv.reader and report each logical row with inclusive one-based physical start/end line numbers. Quoted embedded newlines count as physical lines. Empty input gives no rows; blank physical lines are zero-cell rows. Return [start,end,cells].
Why this case matters
Delimited interchange needs explicit framing, schema and field semantics at ingestion and emission boundaries.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
def _vary(value):
if value == '@END': return 3 + 4*N
if isinstance(value, str): return value.replace('@', 'cell' * N)
if isinstance(value, list): return [_vary(x) for x in value]
if isinstance(value, dict): return {_vary(k): _vary(v) for k,v in value.items()}
return value
N = 1
observations = []
def solve(data):
import csv,io
reader=csv.reader(io.StringIO(data,newline=''))
out=[]; start=1
for cells in reader:
end=reader.line_num
out.append([end,start,cells])
start=end+1
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('multiline', solve(_vary('a,"x\ny"\nz,@\n')), _vary([[1, 2, ['a', 'x\ny']], [3, 3, ['z', '@']]]))
check('blank middle', solve(_vary('a\n\nz\n')), _vary([[1, 1, ['a']], [2, 2, []], [3, 3, ['z']]]))
check('plain', solve(_vary('@,x\n')), _vary([[1, 1, ['@', 'x']]]))
check('CRLF', solve(_vary('"a\r\nb",z\r\n')), _vary([[1, 2, ['a\r\nb', 'z']]]))
check('empty', solve(_vary('')), _vary([]))
check('unterminated final', solve(_vary('@')), _vary([[1, 1, ['@']]]))
check('two multiline', solve(_vary('"a\nb"\n"c\nd"')), _vary([[1, 2, ['a\nb']], [3, 4, ['c\nd']]]))
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 |
|---|---|---|---|
| multiline | [[2, 1, ['a', 'x\ny']], [3, 3, ['z', 'cell']]] | [[1, 2, ['a', 'x\ny']], [3, 3, ['z', 'cell']]] | Failed |
| blank middle | [[1, 1, ['a']], [2, 2, []], [3, 3, ['z']]] | [[1, 1, ['a']], [2, 2, []], [3, 3, ['z']]] | Passed |
| plain | [[1, 1, ['cell', 'x']]] | [[1, 1, ['cell', 'x']]] | Passed |
| CRLF | [[2, 1, ['a\r\nb', 'z']]] | [[1, 2, ['a\r\nb', 'z']]] | Failed |
| empty | [] | [] | Passed |
| unterminated final | [[1, 1, ['cell']]] | [[1, 1, ['cell']]] | Passed |
| two multiline | [[2, 1, ['a\nb']], [4, 3, ['c\nd']]] | [[1, 2, ['a\nb']], [3, 4, ['c\nd']]] | Failed |
SHA-256 / 9634ab427065be3be71fc9d89fb7dc28c068986372e8d840c0b90568faa7850f
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
def _vary(value):
if value == '@END': return 3 + 4*N
if isinstance(value, str): return value.replace('@', 'cell' * N)
if isinstance(value, list): return [_vary(x) for x in value]
if isinstance(value, dict): return {_vary(k): _vary(v) for k,v in value.items()}
return value
N = 1
observations = []
def solve(data):
import csv,io
reader=csv.reader(io.StringIO(data,newline=''))
out=[]; start=1
for cells in reader:
end=reader.line_num
out.append([start,end-start,cells])
start=end+1
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('multiline', solve(_vary('a,"x\ny"\nz,@\n')), _vary([[1, 2, ['a', 'x\ny']], [3, 3, ['z', '@']]]))
check('blank middle', solve(_vary('a\n\nz\n')), _vary([[1, 1, ['a']], [2, 2, []], [3, 3, ['z']]]))
check('plain', solve(_vary('@,x\n')), _vary([[1, 1, ['@', 'x']]]))
check('CRLF', solve(_vary('"a\r\nb",z\r\n')), _vary([[1, 2, ['a\r\nb', 'z']]]))
check('empty', solve(_vary('')), _vary([]))
check('unterminated final', solve(_vary('@')), _vary([[1, 1, ['@']]]))
check('two multiline', solve(_vary('"a\nb"\n"c\nd"')), _vary([[1, 2, ['a\nb']], [3, 4, ['c\nd']]]))
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 |
|---|---|---|---|
| multiline | [[1, 1, ['a', 'x\ny']], [3, 0, ['z', 'cell']]] | [[1, 2, ['a', 'x\ny']], [3, 3, ['z', 'cell']]] | Failed |
| blank middle | [[1, 0, ['a']], [2, 0, []], [3, 0, ['z']]] | [[1, 1, ['a']], [2, 2, []], [3, 3, ['z']]] | Failed |
| plain | [[1, 0, ['cell', 'x']]] | [[1, 1, ['cell', 'x']]] | Failed |
| CRLF | [[1, 1, ['a\r\nb', 'z']]] | [[1, 2, ['a\r\nb', 'z']]] | Failed |
| empty | [] | [] | Passed |
| unterminated final | [[1, 0, ['cell']]] | [[1, 1, ['cell']]] | Failed |
| two multiline | [[1, 1, ['a\nb']], [3, 1, ['c\nd']]] | [[1, 2, ['a\nb']], [3, 4, ['c\nd']]] | Failed |
SHA-256 / 984978926d77b7089da8a9534938c4c796dabf4da87bcbb33f63d9d55ce1af28
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
def _vary(value):
if value == '@END': return 3 + 4*N
if isinstance(value, str): return value.replace('@', 'cell' * N)
if isinstance(value, list): return [_vary(x) for x in value]
if isinstance(value, dict): return {_vary(k): _vary(v) for k,v in value.items()}
return value
N = 1
observations = []
def solve(data):
import csv,io
reader=csv.reader(io.StringIO(data,newline=''))
out=[]; start=1
for cells in reader:
end=reader.line_num
out.append([start,end,cells])
start=end+1
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('multiline', solve(_vary('a,"x\ny"\nz,@\n')), _vary([[1, 2, ['a', 'x\ny']], [3, 3, ['z', '@']]]))
check('blank middle', solve(_vary('a\n\nz\n')), _vary([[1, 1, ['a']], [2, 2, []], [3, 3, ['z']]]))
check('plain', solve(_vary('@,x\n')), _vary([[1, 1, ['@', 'x']]]))
check('CRLF', solve(_vary('"a\r\nb",z\r\n')), _vary([[1, 2, ['a\r\nb', 'z']]]))
check('empty', solve(_vary('')), _vary([]))
check('unterminated final', solve(_vary('@')), _vary([[1, 1, ['@']]]))
check('two multiline', solve(_vary('"a\nb"\n"c\nd"')), _vary([[1, 2, ['a\nb']], [3, 4, ['c\nd']]]))
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 |
|---|---|---|---|
| multiline | [[1, 2, ['a', 'x\ny']], [3, 3, ['z', 'cell']]] | [[1, 2, ['a', 'x\ny']], [3, 3, ['z', 'cell']]] | Passed |
| blank middle | [[1, 1, ['a']], [2, 2, []], [3, 3, ['z']]] | [[1, 1, ['a']], [2, 2, []], [3, 3, ['z']]] | Passed |
| plain | [[1, 1, ['cell', 'x']]] | [[1, 1, ['cell', 'x']]] | Passed |
| CRLF | [[1, 2, ['a\r\nb', 'z']]] | [[1, 2, ['a\r\nb', 'z']]] | Passed |
| empty | [] | [] | Passed |
| unterminated final | [[1, 1, ['cell']]] | [[1, 1, ['cell']]] | Passed |
| two multiline | [[1, 2, ['a\nb']], [3, 4, ['c\nd']]] | [[1, 2, ['a\nb']], [3, 4, ['c\nd']]] | Passed |
SHA-256 / c0dcd833e59189ee8c02f058ae4196f72cb98eb308059eff0a5c0abb27b2d4b0
Verification & scope
Deterministic bounded in-memory model. No claim of complete CSV or external format conformance. 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:44:54.072149+00:00.
Case digest / 16a17c7e63b313aa6fc78a2abcb3fd5e2a29ccf0fe5642dafcbb4b05bee245c4