FAILURE MAP
← Case archive

FA-3921 / Encodings / Open access

A byte-budget truncation returns a partial UTF-8 scalar · case 01

A byte-budget truncation returns a partial UTF-8 scalar.

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: Given scalar text and a nonnegative byte budget, retain the longest UTF-8 prefix ending at a scalar boundary.

THE FAILURE

The implementation applies an operation whose text or grammar semantics violate this contract: Given scalar text and a nonnegative byte budget, retain the longest UTF-8 prefix ending at a scalar boundary.

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

Case contract

Given scalar text and a nonnegative byte budget, retain the longest UTF-8 prefix ending at a scalar boundary.

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 x[0][:x[1]]
    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(['éx', 1]), '')
check('boundary 2', solve(['éx', 2]), 'é')
check('boundary 3', solve(['😀a', 4]), '😀')
check('boundary 4', solve(['abc', 2]), 'ab')
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éFailed
boundary 2éxéFailed
boundary 3😀a😀Failed
boundary 4ababPassed

SHA-256 / 436e5ae7e3e83d6b618ef6617f3ada96299e71cbf0a97813c1e3ce1e11e604c3

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 x[0].encode('utf-8')[:x[1]].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(['éx', 1]), '')
check('boundary 2', solve(['éx', 2]), 'é')
check('boundary 3', solve(['😀a', 4]), '😀')
check('boundary 4', solve(['abc', 2]), 'ab')
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�Failed
boundary 2ééPassed
boundary 3😀😀Passed
boundary 4ababPassed

SHA-256 / ddcdf80b223ab339de538ccd5c93ed00188a56e2f9a4eb073a0b3d05dcd41ce3

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 4 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

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

Case digest / 029527aeb822131c03265e48abed1c65e466115b8fff43692204d7c580d427f4