broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    idx=x['index']
    T=x['total']
    if not idx or T<=0: return None
    reqs=[]
    H=x['header_end']
    if H>0 and not any(a<=0 and H-1<=b for a,b in x['cached']): reqs.append([0,H-1])
    k=-1
    for i,(tm,off) in enumerate(idx):
        if tm<=x['seek']: k=i
    o=idx[max(k,0)][1]
    if o>=T: return None
    e=min(T-1,o+x['window']-1)
    cur=o
    for a,b in sorted(x['cached']):
        if b<cur or a>e: continue
        if a>cur: reqs.append([cur,a-1])
        cur=max(cur,b+1)
    if cur<e: reqs.append([cur,e])
    return ['bytes=%d-%d'%(a,b) for a,b in reqs]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('tail-emit fixture 0', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('tail-emit fixture 1', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2000,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('tail-emit fixture 2', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':3999,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('tail-emit fixture 3', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[1000,100],[3000,600]],'seek':500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=100-399'])))
check('tail-emit fixture 4', json.loads(json.dumps(solve({'cached':[[0,49]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('tail-emit fixture 5', json.loads(json.dumps(solve({'cached':[[50,200]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('tail-emit fixture 6', json.loads(json.dumps(solve({'cached':[[0,150]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-799'])))
check('tail-emit fixture 7', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':4500,'total':1200,'window':400}))), json.loads(json.dumps(['bytes=0-99','bytes=900-1199'])))
check('tail-emit fixture 8', json.loads(json.dumps(solve({'cached':[[0,99],[600,649]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-599','bytes=650-799'])))
check('tail-emit fixture 9', json.loads(json.dumps(solve({'cached':[[0,99],[900,950]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-799'])))
check('tail-emit fixture 10', json.loads(json.dumps(solve({'cached':[[0,99],[799,850]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-798'])))
check('tail-emit fixture 11', json.loads(json.dumps(solve({'cached':[[0,99],[600,610],[540,700]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-539','bytes=701-799'])))
check('tail-emit fixture 12', json.loads(json.dumps(solve({'cached':[[0,99],[500,798]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=799-799'])))
check('tail-emit fixture 13', json.loads(json.dumps(solve({'cached':[[0,99],[500,510]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=511-799'])))
check('tail-emit fixture 14', json.loads(json.dumps(solve({'cached':[[0,99],[501,510]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-500','bytes=511-799'])))
check('tail-emit fixture 15', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,1300]],'seek':3000,'total':1200,'window':300}))), json.loads(json.dumps(None)))
check('tail-emit fixture 16', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':10,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=100-399'])))
check('tail-emit fixture 17', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[1000,200],[2000,300],[3000,400],[4000,500],[5000,600]],'seek':1000*N,'total':2000,'window':50}))), json.loads(json.dumps(['bytes=0-99',"bytes=%d-%d"%(100*N+100,100*N+149)])))
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    idx=x['index']
    T=x['total']
    if not idx or T<=0: return None
    reqs=[]
    H=x['header_end']
    if H>0 and not any(a<=0 and H-1<=b for a,b in x['cached']): reqs.append([0,H-1])
    k=-1
    for i,(tm,off) in enumerate(idx):
        if tm<=x['seek']: k=i
    o=idx[max(k,0)][1]
    if o>=T: return None
    e=min(T-1,o+x['window']-1)
    cur=o
    for a,b in sorted(x['cached']):
        if b<cur or a>e: continue
        if a>cur: reqs.append([cur,a-1])
        cur=max(cur,b+1)
    if cur<=e and cur>o: reqs.append([cur,e])
    return ['bytes=%d-%d'%(a,b) for a,b in reqs]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('tail-emit fixture 0', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('tail-emit fixture 1', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2000,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('tail-emit fixture 2', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':3999,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('tail-emit fixture 3', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[1000,100],[3000,600]],'seek':500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=100-399'])))
check('tail-emit fixture 4', json.loads(json.dumps(solve({'cached':[[0,49]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('tail-emit fixture 5', json.loads(json.dumps(solve({'cached':[[50,200]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('tail-emit fixture 6', json.loads(json.dumps(solve({'cached':[[0,150]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-799'])))
check('tail-emit fixture 7', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':4500,'total':1200,'window':400}))), json.loads(json.dumps(['bytes=0-99','bytes=900-1199'])))
check('tail-emit fixture 8', json.loads(json.dumps(solve({'cached':[[0,99],[600,649]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-599','bytes=650-799'])))
check('tail-emit fixture 9', json.loads(json.dumps(solve({'cached':[[0,99],[900,950]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-799'])))
check('tail-emit fixture 10', json.loads(json.dumps(solve({'cached':[[0,99],[799,850]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-798'])))
check('tail-emit fixture 11', json.loads(json.dumps(solve({'cached':[[0,99],[600,610],[540,700]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-539','bytes=701-799'])))
check('tail-emit fixture 12', json.loads(json.dumps(solve({'cached':[[0,99],[500,798]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=799-799'])))
check('tail-emit fixture 13', json.loads(json.dumps(solve({'cached':[[0,99],[500,510]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=511-799'])))
check('tail-emit fixture 14', json.loads(json.dumps(solve({'cached':[[0,99],[501,510]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-500','bytes=511-799'])))
check('tail-emit fixture 15', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,1300]],'seek':3000,'total':1200,'window':300}))), json.loads(json.dumps(None)))
check('tail-emit fixture 16', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':10,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=100-399'])))
check('tail-emit fixture 17', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[1000,200],[2000,300],[3000,400],[4000,500],[5000,600]],'seek':1000*N,'total':2000,'window':50}))), json.loads(json.dumps(['bytes=0-99',"bytes=%d-%d"%(100*N+100,100*N+149)])))
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)

prompt:
A media player maps a seek time to keyframe-aligned byte range requests around cached spans: a one-byte uncached window tail is still requested.

x has a time-sorted keyframe index [time,byte-offset], total length, init header length H (bytes 0..H-1), seek time, byte window and cached inclusive spans (unordered). Request the header unless one cached span covers all of it. Start at the last keyframe with time<=seek, or the first keyframe when seeking earlier. A start offset at or beyond total, an empty index or nonpositive total returns null. The media window is [start,min(total-1,start+window-1)]; request only its uncached gaps in ascending order, as inclusive bytes=a-b values after any header request.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    idx=x['index']
    T=x['total']
    if not idx or T<=0: return None
    reqs=[]
    H=x['header_end']
    if H>0 and not any(a<=0 and H-1<=b for a,b in x['cached']): reqs.append([0,H-1])
    k=-1
    for i,(tm,off) in enumerate(idx):
        if tm<=x['seek']: k=i
    o=idx[max(k,0)][1]
    if o>=T: return None
    e=min(T-1,o+x['window']-1)
    cur=o
    for a,b in sorted(x['cached']):
        if b<cur or a>e: continue
        if a>=cur: reqs.append([cur,a-1])
        cur=max(cur,b+1)
    if cur<=e: reqs.append([cur,e])
    return ['bytes=%d-%d'%(a,b) for a,b in reqs]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('cached-start-inside fixture 0', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('cached-start-inside fixture 1', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2000,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('cached-start-inside fixture 2', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':3999,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('cached-start-inside fixture 3', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[1000,100],[3000,600]],'seek':500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=100-399'])))
check('cached-start-inside fixture 4', json.loads(json.dumps(solve({'cached':[[0,49]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('cached-start-inside fixture 5', json.loads(json.dumps(solve({'cached':[[50,200]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('cached-start-inside fixture 6', json.loads(json.dumps(solve({'cached':[[0,150]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-799'])))
check('cached-start-inside fixture 7', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':4500,'total':1200,'window':400}))), json.loads(json.dumps(['bytes=0-99','bytes=900-1199'])))
check('cached-start-inside fixture 8', json.loads(json.dumps(solve({'cached':[[0,99],[600,649]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-599','bytes=650-799'])))
check('cached-start-inside fixture 9', json.loads(json.dumps(solve({'cached':[[0,99],[900,950]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-799'])))
check('cached-start-inside fixture 10', json.loads(json.dumps(solve({'cached':[[0,99],[799,850]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-798'])))
check('cached-start-inside fixture 11', json.loads(json.dumps(solve({'cached':[[0,99],[600,610],[540,700]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-539','bytes=701-799'])))
check('cached-start-inside fixture 12', json.loads(json.dumps(solve({'cached':[[0,99],[500,798]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=799-799'])))
check('cached-start-inside fixture 13', json.loads(json.dumps(solve({'cached':[[0,99],[500,510]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=511-799'])))
check('cached-start-inside fixture 14', json.loads(json.dumps(solve({'cached':[[0,99],[501,510]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-500','bytes=511-799'])))
check('cached-start-inside fixture 15', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,1300]],'seek':3000,'total':1200,'window':300}))), json.loads(json.dumps(None)))
check('cached-start-inside fixture 16', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':10,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=100-399'])))
check('cached-start-inside fixture 17', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[1000,200],[2000,300],[3000,400],[4000,500],[5000,600]],'seek':1000*N,'total':2000,'window':50}))), json.loads(json.dumps(['bytes=0-99',"bytes=%d-%d"%(100*N+100,100*N+149)])))
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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    idx=x['index']
    T=x['total']
    if not idx or T<=0: return None
    reqs=[]
    H=x['header_end']
    if H>0 and not any(a<=0 and H-1<=b for a,b in x['cached']): reqs.append([0,H-1])
    k=-1
    for i,(tm,off) in enumerate(idx):
        if tm<=x['seek']: k=i
    o=idx[max(k,0)][1]
    if o>=T: return None
    e=min(T-1,o+x['window']-1)
    cur=o
    for a,b in sorted(x['cached']):
        if b<cur or a>e: continue
        if a>cur+1: reqs.append([cur,a-1])
        cur=max(cur,b+1)
    if cur<=e: reqs.append([cur,e])
    return ['bytes=%d-%d'%(a,b) for a,b in reqs]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('cached-start-inside fixture 0', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('cached-start-inside fixture 1', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2000,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('cached-start-inside fixture 2', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':3999,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('cached-start-inside fixture 3', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[1000,100],[3000,600]],'seek':500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=100-399'])))
check('cached-start-inside fixture 4', json.loads(json.dumps(solve({'cached':[[0,49]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('cached-start-inside fixture 5', json.loads(json.dumps(solve({'cached':[[50,200]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=500-799'])))
check('cached-start-inside fixture 6', json.loads(json.dumps(solve({'cached':[[0,150]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-799'])))
check('cached-start-inside fixture 7', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':4500,'total':1200,'window':400}))), json.loads(json.dumps(['bytes=0-99','bytes=900-1199'])))
check('cached-start-inside fixture 8', json.loads(json.dumps(solve({'cached':[[0,99],[600,649]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-599','bytes=650-799'])))
check('cached-start-inside fixture 9', json.loads(json.dumps(solve({'cached':[[0,99],[900,950]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-799'])))
check('cached-start-inside fixture 10', json.loads(json.dumps(solve({'cached':[[0,99],[799,850]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-798'])))
check('cached-start-inside fixture 11', json.loads(json.dumps(solve({'cached':[[0,99],[600,610],[540,700]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-539','bytes=701-799'])))
check('cached-start-inside fixture 12', json.loads(json.dumps(solve({'cached':[[0,99],[500,798]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=799-799'])))
check('cached-start-inside fixture 13', json.loads(json.dumps(solve({'cached':[[0,99],[500,510]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=511-799'])))
check('cached-start-inside fixture 14', json.loads(json.dumps(solve({'cached':[[0,99],[501,510]],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':2500,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=500-500','bytes=511-799'])))
check('cached-start-inside fixture 15', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,1300]],'seek':3000,'total':1200,'window':300}))), json.loads(json.dumps(None)))
check('cached-start-inside fixture 16', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[2000,500],[4000,900]],'seek':10,'total':1200,'window':300}))), json.loads(json.dumps(['bytes=0-99','bytes=100-399'])))
check('cached-start-inside fixture 17', json.loads(json.dumps(solve({'cached':[],'header_end':100,'index':[[0,100],[1000,200],[2000,300],[3000,400],[4000,500],[5000,600]],'seek':1000*N,'total':2000,'window':50}))), json.loads(json.dumps(['bytes=0-99',"bytes=%d-%d"%(100*N+100,100*N+149)])))
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)

prompt:
A media player maps a seek time to keyframe-aligned byte range requests around cached spans: a cached span beginning at the cursor produces no empty gap request.

x has a time-sorted keyframe index [time,byte-offset], total length, init header length H (bytes 0..H-1), seek time, byte window and cached inclusive spans (unordered). Request the header unless one cached span covers all of it. Start at the last keyframe with time<=seek, or the first keyframe when seeking earlier. A start offset at or beyond total, an empty index or nonpositive total returns null. The media window is [start,min(total-1,start+window-1)]; request only its uncached gaps in ascending order, as inclusive bytes=a-b values after any header request.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-len(data)
    p=len(data)-22
    while p>=0:
        if data[p:p+4]==b'PK\x05\x06': break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+4)
    if disk!=0 or cddisk!=0 or n1!=n2: return [head,None]
    eocd=base+p
    if off+size>eocd: return [head,None]
    if off>=base: return [head,['local',off-base,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size)-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('comment-anchored-eocd fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('comment-anchored-eocd fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('comment-anchored-eocd fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('comment-anchored-eocd fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('comment-anchored-eocd fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('comment-anchored-eocd fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('comment-anchored-eocd fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('comment-anchored-eocd fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('comment-anchored-eocd fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('comment-anchored-eocd fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('comment-anchored-eocd fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('comment-anchored-eocd fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('comment-anchored-eocd fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('comment-anchored-eocd fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('comment-anchored-eocd fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('comment-anchored-eocd fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-len(data)
    p=len(data)-22
    while p>=0:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')<=len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+4)
    if disk!=0 or cddisk!=0 or n1!=n2: return [head,None]
    eocd=base+p
    if off+size>eocd: return [head,None]
    if off>=base: return [head,['local',off-base,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size)-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('comment-anchored-eocd fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('comment-anchored-eocd fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('comment-anchored-eocd fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('comment-anchored-eocd fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('comment-anchored-eocd fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('comment-anchored-eocd fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('comment-anchored-eocd fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('comment-anchored-eocd fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('comment-anchored-eocd fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('comment-anchored-eocd fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('comment-anchored-eocd fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('comment-anchored-eocd fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('comment-anchored-eocd fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('comment-anchored-eocd fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('comment-anchored-eocd fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('comment-anchored-eocd fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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)

prompt:
A remote archive reader locates the central directory from a suffix range response: a signature inside the archive comment is not accepted as the end record.

x has total representation length, requested suffix length and the hex bytes of the suffix response (the last min(total,suffix) bytes). Emit the suffix Range value (null when it would be zero bytes). Scan backward for the end record signature PK\x05\x06 whose little-endian comment length makes the 22-byte record plus comment end exactly at the tail end. Reject multi-disk archives (disk or directory disk nonzero, or differing entry counts) and a directory that extends past the end record. A directory starting inside the tail is ["local",tail-index,size]; otherwise request only the missing prefix before the tail as ["fetch",inclusive range]. Output [suffix-range,plan-or-null].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-len(data)
    p=len(data)-22
    while p>=0:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')==len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p)
    if disk!=0 or cddisk!=0 or n1!=n2: return [head,None]
    eocd=base+p
    if off+size>eocd: return [head,None]
    if off>=base: return [head,['local',off-base,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size)-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('record-offset fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('record-offset fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('record-offset fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('record-offset fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('record-offset fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('record-offset fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('record-offset fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('record-offset fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('record-offset fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('record-offset fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('record-offset fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('record-offset fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('record-offset fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('record-offset fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('record-offset fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('record-offset fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-len(data)
    p=len(data)-22
    while p>=0:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')==len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+2)
    if disk!=0 or cddisk!=0 or n1!=n2: return [head,None]
    eocd=base+p
    if off+size>eocd: return [head,None]
    if off>=base: return [head,['local',off-base,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size)-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('record-offset fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('record-offset fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('record-offset fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('record-offset fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('record-offset fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('record-offset fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('record-offset fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('record-offset fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('record-offset fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('record-offset fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('record-offset fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('record-offset fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('record-offset fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('record-offset fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('record-offset fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('record-offset fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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)

prompt:
A remote archive reader locates the central directory from a suffix range response: end-record fields are decoded after the four signature bytes.

x has total representation length, requested suffix length and the hex bytes of the suffix response (the last min(total,suffix) bytes). Emit the suffix Range value (null when it would be zero bytes). Scan backward for the end record signature PK\x05\x06 whose little-endian comment length makes the 22-byte record plus comment end exactly at the tail end. Reject multi-disk archives (disk or directory disk nonzero, or differing entry counts) and a directory that extends past the end record. A directory starting inside the tail is ["local",tail-index,size]; otherwise request only the missing prefix before the tail as ["fetch",inclusive range]. Output [suffix-range,plan-or-null].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-len(data)
    p=len(data)-22
    while p>=0:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')==len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+4)
    if disk!=0: return [head,None]
    eocd=base+p
    if off+size>eocd: return [head,None]
    if off>=base: return [head,['local',off-base,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size)-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('single-disk-archive fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('single-disk-archive fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('single-disk-archive fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('single-disk-archive fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('single-disk-archive fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('single-disk-archive fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('single-disk-archive fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('single-disk-archive fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('single-disk-archive fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('single-disk-archive fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('single-disk-archive fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('single-disk-archive fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('single-disk-archive fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('single-disk-archive fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('single-disk-archive fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('single-disk-archive fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-len(data)
    p=len(data)-22
    while p>=0:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')==len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+4)
    if disk!=cddisk: return [head,None]
    eocd=base+p
    if off+size>eocd: return [head,None]
    if off>=base: return [head,['local',off-base,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size)-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('single-disk-archive fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('single-disk-archive fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('single-disk-archive fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('single-disk-archive fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('single-disk-archive fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('single-disk-archive fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('single-disk-archive fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('single-disk-archive fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('single-disk-archive fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('single-disk-archive fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('single-disk-archive fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('single-disk-archive fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('single-disk-archive fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('single-disk-archive fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('single-disk-archive fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('single-disk-archive fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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)

prompt:
A remote archive reader locates the central directory from a suffix range response: split archives are rejected by disk numbers and entry totals.

x has total representation length, requested suffix length and the hex bytes of the suffix response (the last min(total,suffix) bytes). Emit the suffix Range value (null when it would be zero bytes). Scan backward for the end record signature PK\x05\x06 whose little-endian comment length makes the 22-byte record plus comment end exactly at the tail end. Reject multi-disk archives (disk or directory disk nonzero, or differing entry counts) and a directory that extends past the end record. A directory starting inside the tail is ["local",tail-index,size]; otherwise request only the missing prefix before the tail as ["fetch",inclusive range]. Output [suffix-range,plan-or-null].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-len(data)
    p=len(data)-22
    while p>=0:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')==len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+4)
    if disk!=0 or cddisk!=0 or n1!=n2: return [head,None]
    eocd=base+p
    if off>eocd: return [head,None]
    if off>=base: return [head,['local',off-base,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size)-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('directory-bounds fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('directory-bounds fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('directory-bounds fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('directory-bounds fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('directory-bounds fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('directory-bounds fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('directory-bounds fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('directory-bounds fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('directory-bounds fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('directory-bounds fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('directory-bounds fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('directory-bounds fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('directory-bounds fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('directory-bounds fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('directory-bounds fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('directory-bounds fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-len(data)
    p=len(data)-22
    while p>=0:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')==len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+4)
    if disk!=0 or cddisk!=0 or n1!=n2: return [head,None]
    eocd=base+p
    if off+size>eocd+22: return [head,None]
    if off>=base: return [head,['local',off-base,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size)-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('directory-bounds fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('directory-bounds fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('directory-bounds fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('directory-bounds fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('directory-bounds fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('directory-bounds fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('directory-bounds fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('directory-bounds fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('directory-bounds fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('directory-bounds fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('directory-bounds fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('directory-bounds fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('directory-bounds fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('directory-bounds fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('directory-bounds fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('directory-bounds fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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)

prompt:
A remote archive reader locates the central directory from a suffix range response: the central directory must end before the end record begins.

x has total representation length, requested suffix length and the hex bytes of the suffix response (the last min(total,suffix) bytes). Emit the suffix Range value (null when it would be zero bytes). Scan backward for the end record signature PK\x05\x06 whose little-endian comment length makes the 22-byte record plus comment end exactly at the tail end. Reject multi-disk archives (disk or directory disk nonzero, or differing entry counts) and a directory that extends past the end record. A directory starting inside the tail is ["local",tail-index,size]; otherwise request only the missing prefix before the tail as ["fetch",inclusive range]. Output [suffix-range,plan-or-null].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=0
    p=len(data)-22
    while p>=0:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')==len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+4)
    if disk!=0 or cddisk!=0 or n1!=n2: return [head,None]
    eocd=base+p
    if off+size>eocd: return [head,None]
    if off>=base: return [head,['local',off-base,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size)-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('tail-absolute-base fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('tail-absolute-base fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('tail-absolute-base fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('tail-absolute-base fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('tail-absolute-base fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('tail-absolute-base fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('tail-absolute-base fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('tail-absolute-base fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('tail-absolute-base fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('tail-absolute-base fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('tail-absolute-base fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('tail-absolute-base fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('tail-absolute-base fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('tail-absolute-base fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('tail-absolute-base fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('tail-absolute-base fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-x['suffix']
    p=len(data)-22
    while p>=0:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')==len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+4)
    if disk!=0 or cddisk!=0 or n1!=n2: return [head,None]
    eocd=base+p
    if off+size>eocd: return [head,None]
    if off>=base: return [head,['local',off-base,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size)-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('tail-absolute-base fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('tail-absolute-base fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('tail-absolute-base fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('tail-absolute-base fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('tail-absolute-base fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('tail-absolute-base fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('tail-absolute-base fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('tail-absolute-base fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('tail-absolute-base fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('tail-absolute-base fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('tail-absolute-base fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('tail-absolute-base fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('tail-absolute-base fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('tail-absolute-base fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('tail-absolute-base fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('tail-absolute-base fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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)

prompt:
A remote archive reader locates the central directory from a suffix range response: tail indexes are rebased by the actual suffix length received.

x has total representation length, requested suffix length and the hex bytes of the suffix response (the last min(total,suffix) bytes). Emit the suffix Range value (null when it would be zero bytes). Scan backward for the end record signature PK\x05\x06 whose little-endian comment length makes the 22-byte record plus comment end exactly at the tail end. Reject multi-disk archives (disk or directory disk nonzero, or differing entry counts) and a directory that extends past the end record. A directory starting inside the tail is ["local",tail-index,size]; otherwise request only the missing prefix before the tail as ["fetch",inclusive range]. Output [suffix-range,plan-or-null].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-len(data)
    p=len(data)-22
    while p>=0:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')==len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+4)
    if disk!=0 or cddisk!=0 or n1!=n2: return [head,None]
    eocd=base+p
    if off+size>eocd: return [head,None]
    if off>base: return [head,['local',off-base,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size)-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('directory-in-tail fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('directory-in-tail fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('directory-in-tail fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('directory-in-tail fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('directory-in-tail fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('directory-in-tail fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('directory-in-tail fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('directory-in-tail fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('directory-in-tail fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('directory-in-tail fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('directory-in-tail fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('directory-in-tail fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('directory-in-tail fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('directory-in-tail fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('directory-in-tail fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('directory-in-tail fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-len(data)
    p=len(data)-22
    while p>=0:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')==len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+4)
    if disk!=0 or cddisk!=0 or n1!=n2: return [head,None]
    eocd=base+p
    if off+size>eocd: return [head,None]
    if off+size>=base: return [head,['local',off-base,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size)-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('directory-in-tail fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('directory-in-tail fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('directory-in-tail fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('directory-in-tail fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('directory-in-tail fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('directory-in-tail fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('directory-in-tail fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('directory-in-tail fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('directory-in-tail fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('directory-in-tail fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('directory-in-tail fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('directory-in-tail fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('directory-in-tail fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('directory-in-tail fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('directory-in-tail fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('directory-in-tail fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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)

prompt:
A remote archive reader locates the central directory from a suffix range response: only a directory starting inside the tail is served locally.

x has total representation length, requested suffix length and the hex bytes of the suffix response (the last min(total,suffix) bytes). Emit the suffix Range value (null when it would be zero bytes). Scan backward for the end record signature PK\x05\x06 whose little-endian comment length makes the 22-byte record plus comment end exactly at the tail end. Reject multi-disk archives (disk or directory disk nonzero, or differing entry counts) and a directory that extends past the end record. A directory starting inside the tail is ["local",tail-index,size]; otherwise request only the missing prefix before the tail as ["fetch",inclusive range]. Output [suffix-range,plan-or-null].

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-len(data)
    p=len(data)-22
    while p>=0:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')==len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+4)
    if disk!=0 or cddisk!=0 or n1!=n2: return [head,None]
    eocd=base+p
    if off+size>eocd: return [head,None]
    if off>=base: return [head,['local',off-base,size]]
    return [head,['fetch','bytes=%d-%d'%(off,off+size-1)]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fetch-missing-prefix fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('fetch-missing-prefix fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('fetch-missing-prefix fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('fetch-missing-prefix fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('fetch-missing-prefix fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('fetch-missing-prefix fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('fetch-missing-prefix fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('fetch-missing-prefix fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('fetch-missing-prefix fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('fetch-missing-prefix fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('fetch-missing-prefix fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('fetch-missing-prefix fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('fetch-missing-prefix fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('fetch-missing-prefix fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('fetch-missing-prefix fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('fetch-missing-prefix fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    import struct
    T=x['total']
    want=min(T,x['suffix'])
    head='bytes=-%d'%want if want>0 else None
    data=bytes.fromhex(x['tail'])
    base=T-len(data)
    p=len(data)-22
    while p>=0:
        if data[p:p+4]==b'PK\x05\x06' and p+22+int.from_bytes(data[p+20:p+22],'little')==len(data): break
        p-=1
    if p<0: return [head,None]
    disk,cddisk,n1,n2,size,off=struct.unpack_from('<HHHHII',data,p+4)
    if disk!=0 or cddisk!=0 or n1!=n2: return [head,None]
    eocd=base+p
    if off+size>eocd: return [head,None]
    if off>=base: return [head,['local',off-base,size]]
    return [head,['fetch','bytes=%d-%d'%(off,min(base,off+size))]]
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('fetch-missing-prefix fixture 0', json.loads(json.dumps(solve({'suffix':64,'tail':'0101010101010101010101010101010101010101434343434343434343434343434343434343504b0506000000000100010012000000140000000000','total':60}))), json.loads(json.dumps(['bytes=-60',['local',20,18]])))
check('fetch-missing-prefix fixture 1', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',['local',0,18]])))
check('fetch-missing-prefix fixture 2', json.loads(json.dumps(solve({'suffix':50,'tail':'43434343434343434343434343434343434300000000000000000000504b0506000000000100010012000000b60300000000','total':1000}))), json.loads(json.dumps(['bytes=-50',['local',0,18]])))
check('fetch-missing-prefix fixture 3', json.loads(json.dumps(solve({'suffix':30,'tail':'4343434343434343504b0506000000000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-30',['fetch','bytes=960-969']])))
check('fetch-missing-prefix fixture 4', json.loads(json.dumps(solve({'suffix':22,'tail':'504b050600000000010001004e000000840300000000','total':1000}))), json.loads(json.dumps(['bytes=-22',['fetch','bytes=900-977']])))
check('fetch-missing-prefix fixture 5', json.loads(json.dumps(solve({'suffix':25,'tail':'504b050600000000010001004b000000840300000300616263','total':1000}))), json.loads(json.dumps(['bytes=-25',['fetch','bytes=900-974']])))
check('fetch-missing-prefix fixture 6', json.loads(json.dumps(solve({'suffix':80,'tail':'434343434343434343434343434343434343504b0506000000000100010012000000880000001800504b05060000000001000100000000000000000000007a7a','total':200}))), json.loads(json.dumps(['bytes=-80',['local',0,18]])))
check('fetch-missing-prefix fixture 7', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('fetch-missing-prefix fixture 8', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506010001000100010012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('fetch-missing-prefix fixture 9', json.loads(json.dumps(solve({'suffix':40,'tail':'434343434343434343434343434343434343504b0506000000000100020012000000c00300000000','total':1000}))), json.loads(json.dumps(['bytes=-40',None])))
check('fetch-missing-prefix fixture 10', json.loads(json.dumps(solve({'suffix':100,'tail':'02020202020202020202020202020202020202020202020202020202020202020202020202020202504b05060000000001000100140000001e0000000000','total':62}))), json.loads(json.dumps(['bytes=-62',None])))
check('fetch-missing-prefix fixture 11', json.loads(json.dumps(solve({'suffix':30,'tail':'030303030303030303030303030303030303030303030303030303030303','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('fetch-missing-prefix fixture 12', json.loads(json.dumps(solve({'suffix':30,'tail':'000000000000000000000000000000000000000000000000000000000000','total':30}))), json.loads(json.dumps(['bytes=-30',None])))
check('fetch-missing-prefix fixture 13', json.loads(json.dumps(solve({'suffix':64,'tail':'','total':0}))), json.loads(json.dumps([None,None])))
check('fetch-missing-prefix fixture 14', json.loads(json.dumps(solve({'suffix':64,'tail':'504b0506000000000000000000000000000000000000','total':22}))), json.loads(json.dumps(['bytes=-22',['local',0,0]])))
check('fetch-missing-prefix fixture 15', json.loads(json.dumps(solve({'suffix':32+N,'tail':"11"*10+"504b0506"+"00000000"+"01000100"+"0a000000"+(468-N).to_bytes(4,"little").hex()+(N).to_bytes(2,"little").hex()+"63"*N,'total':500}))), json.loads(json.dumps(["bytes=-%d"%(32+N),['local',0,10]])))
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)

prompt:
A remote archive reader locates the central directory from a suffix range response: the follow-up range stops before bytes already present in the tail.

x has total representation length, requested suffix length and the hex bytes of the suffix response (the last min(total,suffix) bytes). Emit the suffix Range value (null when it would be zero bytes). Scan backward for the end record signature PK\x05\x06 whose little-endian comment length makes the 22-byte record plus comment end exactly at the tail end. Reject multi-disk archives (disk or directory disk nonzero, or differing entry counts) and a directory that extends past the end record. A directory starting inside the tail is ["local",tail-index,size]; otherwise request only the missing prefix before the tail as ["fetch",inclusive range]. Output [suffix-range,plan-or-null].

split: open-access