{"record":{"id":"0585a4d98fdbfcfc","repo":"NationalSecurityAgency/ghidra","slug":"invalid-byte-order-byte-order","errorCode":null,"errorMessage":"Invalid byte_order: {byte_order}","messagePattern":"Invalid byte_order: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/arch.py","lineNumber":253,"sourceCode":"        raise ValueError(f\"Address {address} is not in inferior {inf.num}\")\n\n\nDEFAULT_MEMORY_MAPPER = DefaultMemoryMapper('ram')\n\nmemory_mappers: Dict[str, DefaultMemoryMapper] = {}\n\n\ndef compute_memory_mapper(lang: str) -> DefaultMemoryMapper:\n    if not lang in memory_mappers:\n        return DEFAULT_MEMORY_MAPPER\n    return memory_mappers[lang]\n\n\nclass DefaultRegisterMapper(object):\n\n    def __init__(self, byte_order: str) -> None:\n        if not byte_order in ['big', 'little']:\n            raise ValueError(f\"Invalid byte_order: {byte_order}\")\n        self.byte_order = byte_order\n\n    def map_name(self, inf: gdb.Inferior, name: str):\n        return name\n\n    def convert_value(self, value: gdb.Value,\n                      type: Optional[gdb.Type] = None) -> bytes:\n        if type is None:\n            type = value.dynamic_type.strip_typedefs()\n        l = type.sizeof\n        # l - 1 because array() takes the max index, inclusive\n        # NOTE: Might like to pre-lookup 'unsigned char', but it depends on the\n        # architecture *at the time of lookup*.\n        cv = value.cast(gdb.lookup_type('unsigned char').array(l - 1))\n        rng: Sequence[int] = range(l)\n        it = reversed(rng) if self.byte_order == 'little' else rng\n        result = bytes(cv[i] for i in it)\n        return result","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-agent-gdb/src/main/py/src/ghidragdb/arch.py#L235-L271","documentation":"Thrown as a ValueError by DefaultRegisterMapper.__init__ in the gdb agent when the byte_order argument is not one of the two accepted strings 'big' or 'little'. The constructor validates byte ordering up front because it determines how register byte sequences are serialized.","triggerScenarios":"Calling DefaultRegisterMapper('big-endian'), DefaultRegisterMapper('LE'), DefaultRegisterMapper('none'), or any byte_order string other than exactly 'big' or 'little'. Also fires if None is passed (since None is not in the list).","commonSituations":"Reading endianness from a config or arch-detection function that returns a different format (e.g. 'big-endian', 'BE', 'little-endian', 0/1); passing a GDB architecture's endian field directly without normalization; defaulting to None when arch detection fails.","solutions":["Pass exactly 'big' or 'little' as the byte_order string.","Normalize arch endianness before constructing the mapper: map 'big-endian'/'BE'/1 to 'big' and 'little-endian'/'LE'/0 to 'little'.","If endianness is unknown, default to 'little' for x86/x64 or detect via gdb.execute('show endian')."],"exampleFix":"// before\nmapper = DefaultRegisterMapper(gdb.execute('show endian', to_string=True))\n// after\nendian_raw = gdb.execute('show endian', to_string=True)\nbyte_order = 'little' if 'little' in endian_raw else 'big'\nmapper = DefaultRegisterMapper(byte_order)","handlingStrategy":"validation","validationCode":"def normalize_byte_order(byte_order: str) -> str:\n    bo = byte_order.strip().lower()\n    aliases = {\n        'big': 'big', 'big-endian': 'big', 'be': 'big', 'msb': 'big', '1': 'big',\n        'little': 'little', 'little-endian': 'little', 'le': 'little', 'lsb': 'little', '0': 'little',\n    }\n    if bo not in aliases:\n        raise ValueError(f\"Cannot normalize byte_order: {byte_order!r}\")\n    return aliases[bo]\n\nmapper = DefaultRegisterMapper(normalize_byte_order(raw_endian))","typeGuard":"def is_valid_byte_order(byte_order: str) -> bool:\n    return byte_order in ('big', 'little')","tryCatchPattern":"try:\n    mapper = DefaultRegisterMapper(byte_order)\nexcept ValueError as e:\n    if 'Invalid byte_order' in str(e):\n        byte_order = 'little' if 'little' in byte_order.lower() else 'big'\n        mapper = DefaultRegisterMapper(byte_order)\n    raise","preventionTips":["Normalize endianness strings to exactly 'big' or 'little' before constructing the mapper.","Handle GDB's 'show endian' output format (e.g. 'The target endianness is set automatically (currently little endian)') by keyword search.","Default to 'little' for x86/x64 architectures when in doubt."],"tags":["gdb","configuration","endianness","input-validation"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}