FAILURE MAP
← Case archive

FA-3616 / Binary formats / Open access

A sign-magnitude octet is decoded as two-complement · case 01

A sign-magnitude octet is decoded as two-complement.

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 high-bit sign and seven-bit magnitude, with either zero representation mapping to zero.

VERIFIED REPAIR

Implement the complete stated contract, including the boundary fixtures: Decode high-bit sign and seven-bit magnitude, with either zero representation mapping to zero.

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

Case contract

Decode high-bit sign and seven-bit magnitude, with either zero representation mapping to zero.

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-256 if x>=128 else 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(129), -1)
check('boundary 2', solve(255), -127)
check('boundary 3', solve(128), 0)
check('boundary 4', solve(7), 7)
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-127-1Failed
boundary 2-1-127Failed
boundary 3-1280Failed
boundary 477Passed

SHA-256 / 287ecb6231b58f4d0412e4cccc77b76c26d567230e15a3b26be58409c1696f0d

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 if x>=128 else 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(129), -1)
check('boundary 2', solve(255), -127)
check('boundary 3', solve(128), 0)
check('boundary 4', solve(7), 7)
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-129-1Failed
boundary 2-255-127Failed
boundary 3-1280Failed
boundary 477Passed

SHA-256 / 11fa1c16a791ed4cb7c407407a691e4112df4d0e4c68fc3ae5c27660ef79f817

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 -(x&127) if x&128 else 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(129), -1)
check('boundary 2', solve(255), -127)
check('boundary 3', solve(128), 0)
check('boundary 4', solve(7), 7)
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-1-1Passed
boundary 2-127-127Passed
boundary 300Passed
boundary 477Passed

SHA-256 / 56e69e9c356f0a0c6c029e6c3719c642d73c830d54451fe48908a88f13726143

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

Case digest / c91c446b953491dd0e3fc749abca7b32a3d9d2d69443f9643a69ef0368656583