FAILURE MAP
← Case archive

FA-2966 / Encodings / Open access

Undecodable bytes cannot be re-encoded losslessly · case 01

Undecodable bytes cannot be re-encoded losslessly.

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

ROOT CAUSE

The implementation applies an operation whose text or grammar semantics violate this contract: Decode UTF-8 with surrogateescape and return code point ordinals.

VERIFIED REPAIR

Implement the complete stated contract, including the boundary fixtures: Decode UTF-8 with surrogateescape and return code point ordinals.

Unsuccessful approach: The attempted repair handles the primary example but still violates a separate boundary of the same contract.

Case contract

Decode UTF-8 with surrogateescape and return code point ordinals.

Why this case matters

A local executable model for consumers of structured text; oracle values are authored literals, not outputs copied from the repaired implementation.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import re, unicodedata, json, csv, io, html, base64, binascii, codecs, struct
from urllib.parse import quote, unquote, unquote_to_bytes, urlencode, parse_qsl, urlsplit, urlunsplit
from email.header import decode_header, make_header
from email.utils import getaddresses
from xml.etree import ElementTree as ET
import shlex, string, textwrap

N = 1
observations = []
def solve(x):
    try:
        return list(map(ord,bytes.fromhex(x).decode('utf-8','replace')))
    except Exception as exc:
        return {"error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('boundary 1', solve('ff'), [56575])
check('boundary 2', solve('c3a9'), [233])
check('boundary 3', solve('41'), [65])
check('boundary 4', solve('80'), [56448])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
boundary 1[65533][56575]Failed
boundary 2[233][233]Passed
boundary 3[65][65]Passed
boundary 4[65533][56448]Failed

SHA-256 / 41a8ecddc73cc2698ff59cf00c46ced2438c08d1d13edca6ddd57958b7785f11

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import re, unicodedata, json, csv, io, html, base64, binascii, codecs, struct
from urllib.parse import quote, unquote, unquote_to_bytes, urlencode, parse_qsl, urlsplit, urlunsplit
from email.header import decode_header, make_header
from email.utils import getaddresses
from xml.etree import ElementTree as ET
import shlex, string, textwrap

N = 1
observations = []
def solve(x):
    try:
        return list(bytes.fromhex(x))
    except Exception as exc:
        return {"error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('boundary 1', solve('ff'), [56575])
check('boundary 2', solve('c3a9'), [233])
check('boundary 3', solve('41'), [65])
check('boundary 4', solve('80'), [56448])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
boundary 1[255][56575]Failed
boundary 2[195, 169][233]Failed
boundary 3[65][65]Passed
boundary 4[128][56448]Failed

SHA-256 / 81b0d3393a71c7c6e052382c2149db1aab04484ffb66e83e6e317c3f7e87a5b9

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import re, unicodedata, json, csv, io, html, base64, binascii, codecs, struct
from urllib.parse import quote, unquote, unquote_to_bytes, urlencode, parse_qsl, urlsplit, urlunsplit
from email.header import decode_header, make_header
from email.utils import getaddresses
from xml.etree import ElementTree as ET
import shlex, string, textwrap

N = 1
observations = []
def solve(x):
    try:
        return list(map(ord,bytes.fromhex(x).decode('utf-8','surrogateescape')))
    except Exception as exc:
        return {"error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('boundary 1', solve('ff'), [56575])
check('boundary 2', solve('c3a9'), [233])
check('boundary 3', solve('41'), [65])
check('boundary 4', solve('80'), [56448])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
boundary 1[56575][56575]Passed
boundary 2[233][233]Passed
boundary 3[65][65]Passed
boundary 4[56448][56448]Passed

SHA-256 / e400ab45108715c7a0f1a8bb2e9be6b5f909142fd134469203ef97105c30442d

Verification & scope

This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:37:19.569613+00:00.

Case digest / 9fcd50dd527e3423ab136a24464e10c7ae0c27e3d4aa09bc99355e5da36ad4fb