{"record":{"id":"b886328da562b1b3","repo":"NationalSecurityAgency/ghidra","slug":"cannot-convert-length-to-length-b88632","errorCode":null,"errorMessage":"Cannot convert '{length}' to length","messagePattern":"Cannot convert '(.+?)' to length","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-agent-x64dbg/src/main/py/src/ghidraxdbg/commands.py","lineNumber":472,"sourceCode":"\n\ndef eval_address(address: Union[str, int]) -> int:\n    try:\n        result = util.parse_and_eval(address)\n        if isinstance(result, int):\n            return result\n        raise ValueError(f\"Value '{address}' does not evaluate to an int\")\n    except Exception:\n        raise RuntimeError(f\"Cannot convert '{address}' to address\")\n\n\ndef eval_range(address: Union[str, int],\n               length: Union[str, int]) -> Tuple[int, int]:\n    start = eval_address(address)\n    try:\n        l = util.parse_and_eval(length)\n    except Exception as e:\n        raise RuntimeError(f\"Cannot convert '{length}' to length\")\n    if not isinstance(l, int):\n        raise ValueError(f\"Value '{address}' does not evaluate to an int\")\n    end = start + l\n    return start, end\n\n\ndef putmem(address: Union[str, int], length: Union[str, int],\n           pages: bool = True, display_result: bool = True) -> Dict[str, int]:\n    start, end = eval_range(address, length)\n    return put_bytes(start, end, pages, display_result)\n\n\ndef ghidra_trace_putmem(address: Union[str, int], length: Union[str, int],\n                        pages: bool = True) -> Dict[str, int]:\n    \"\"\"Record the given block of memory into the Ghidra trace.\"\"\"\n\n    STATE.require_tx()\n    return putmem(address, length, pages, True)","sourceCodeStart":454,"sourceCodeEnd":490,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-x64dbg/src/main/py/src/ghidraxdbg/commands.py#L454-L490","documentation":"Raised by eval_range (commands.py:471-472) when util.parse_and_eval(length) throws any exception. The length is parsed independently of the address; failure to evaluate the length expression produces this RuntimeError.","triggerScenarios":"Calling eval_range / putmem / ghidra_trace_putmem / delmem / putmem_state with a length argument that parse_and_eval cannot resolve: an undefined symbol, malformed expression, or empty string for length.","commonSituations":"Passing a symbolic size that is not defined; a length field left blank or set to a non-numeric expression; querying memory ranges before symbols load.","solutions":["Pass a numeric length or a known-resolvable size expression, e.g. putmem(addr, 0x100).","Validate the length expression with util.parse_and_eval first.","Use a literal integer length to avoid evaluator dependency."],"exampleFix":"// before\nputmem(0x00400000, 'sizeof_unknown')  # -> Cannot convert 'sizeof_unknown' to length\n\n// after\nputmem(0x00400000, 0x100)","handlingStrategy":"try-catch","validationCode":"def try_eval_length(length):\n    try:\n        l = util.parse_and_eval(length)\n    except Exception:\n        return int(length, 0) if isinstance(length, str) else int(length)\n    return l","typeGuard":"def is_evaluatable_length(length) -> bool:\n    try:\n        util.parse_and_eval(length)\n        return True\n    except Exception:\n        return isinstance(length, int)","tryCatchPattern":"try:\n    putmem(address, length)\nexcept RuntimeError as e:\n    if 'Cannot convert' in str(e) and 'to length' in str(e):\n        length = int(length, 0) if isinstance(length, str) else int(length)\n        putmem(address, length)\n    else:\n        raise","preventionTips":["Use literal integer lengths to avoid evaluator failures.","Validate the length expression with parse_and_eval before memory commands.","Confirm symbols/sizes are loaded before referencing them by name."],"tags":["evaluation","length-parsing","trace-agent","python"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}