NationalSecurityAgency/ghidra · error · ValueError

Cannot convert {}'s value: '{}', type: '{}'

Error message

Cannot convert {}'s value: '{}', type: '{}'

What it means

Thrown by DefaultRegisterMapper.map_value() when converting a register value to an 8-byte big-endian representation fails. The method calls value.to_bytes(8, 'big'), and if the value is not an integer or doesn't fit in 8 bytes, the exception is caught and re-raised as ValueError with the register name, value, and type. This indicates the register value from the debugger is in an unexpected format.

Source

Thrown at Ghidra/Debug/Debugger-agent-dbgeng/src/main/py/src/ghidradbg/arch.py:249

    return memory_mappers[lang]


class DefaultRegisterMapper(object):

    def __init__(self, byte_order: str) -> None:
        if not byte_order in ['big', 'little']:
            raise ValueError("Invalid byte_order: {}".format(byte_order))
        self.byte_order = byte_order

    def map_name(self, proc: int, name: str):
        return name

    def map_value(self, proc: int, name: str, value: int):
        try:
            # TODO: this seems half-baked
            av = value.to_bytes(8, "big")
        except Exception:
            raise ValueError("Cannot convert {}'s value: '{}', type: '{}'"
                             .format(name, value, type(value)))
        return RegVal(self.map_name(proc, name), av)

    def map_name_back(self, proc: int, name: str) -> str:
        return name

    def map_value_back(self, proc: int, name: str, value: bytes):
        return RegVal(self.map_name_back(proc, name), value)


class Intel_x86_64_RegisterMapper(DefaultRegisterMapper):

    def __init__(self):
        super().__init__('little')

    def map_name(self, proc, name):
        if name is None:
            return 'UNKNOWN'

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Check the type and magnitude of the value before calling map_value — convert to a non-negative int first.
  2. If the register is wider than 64 bits, subclass DefaultRegisterMapper and handle larger sizes.
  3. Fix the upstream code that provides register values to ensure they're ints in [0, 2^64).
  4. Add explicit type conversion: int(value) with appropriate bounds checking.

Example fix

# Before:
# mapper.map_value(proc, name, raw_value)  # raw_value may be str or negative
#
# After:
# val = int(raw_value) if not isinstance(raw_value, int) else raw_value
# val = val & 0xFFFFFFFFFFFFFFFF  # mask to unsigned 64-bit
# mapper.map_value(proc, name, val)
Defensive patterns

Strategy: validation

Validate before calling

# Before calling map_value, ensure value is a non-negative int fitting in 8 bytes:
if isinstance(value, int) and 0 <= value < (1 << 64):
    result = mapper.map_value(proc, name, value)
else:
    value = int(value) & 0xFFFFFFFFFFFFFFFF
    result = mapper.map_value(proc, name, value)

Type guard

def is_valid_register_value(value) -> bool:
    return isinstance(value, int) and 0 <= value < (1 << 64)

Try / catch

try:
    result = mapper.map_value(proc, name, value)
except ValueError as e:
    if 'Cannot convert' in str(e):
        # coerce to int and mask, then retry
        value = int(value) & 0xFFFFFFFFFFFFFFFF
        result = mapper.map_value(proc, name, value)
    else:
        raise

Prevention

When it happens

Trigger: map_value(proc, name, value) calls value.to_bytes(8, 'big'). This fails if value is not an int (e.g., it's a float, string, or None), or if the int is negative, or if it exceeds 8 bytes (larger than 2^64-1). The generic except clause wraps the original exception into a ValueError with diagnostic info.

Common situations: The debugger returns a register value as a string or bytearray instead of an int. A 128-bit register (e.g., AVX/SSE) value exceeds the 8-byte limit. A negative value is returned where unsigned is expected. The dbgeng bridge returns register values in a format the mapper doesn't expect.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/7f76bb2757fa049c. Report an issue: GitHub.