{"record":{"id":"9dba8ebb4a58a813","repo":"NationalSecurityAgency/ghidra","slug":"cannot-receive-tracermi-message-with-excessive-mes-9dba8e","errorCode":null,"errorMessage":"Cannot receive TraceRmi message with excessive message length","messagePattern":"Cannot receive TraceRmi message with excessive message length","errorType":"exception","errorClass":"TraceRmiError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-rmi-trace/src/main/py/src/ghidratrace/util.py","lineNumber":60,"sourceCode":"        part = s.recv(size - len(buf))\n        if len(part) == 0:\n            return buf\n        buf += part\n    return buf\n    # return s.recv(size, socket.MSG_WAITALL)\n\n\ndef recv_length(s: socket.socket) -> int:\n    buf = recv_all(s, 4)\n    if len(buf) < 4:\n        raise Exception(\"Socket closed\")\n    return int.from_bytes(buf, 'big')\n\n\ndef recv_delimited(s: socket.socket, msg: M, dbg_seq: int) -> M:\n    size = recv_length(s)\n    if size > MAX_MSG_LENGTH:\n        raise TraceRmiError(\"Cannot receive TraceRmi message with excessive message length\")\n    buf = recv_all(s, size)\n    if len(buf) < size:\n        raise Exception(\"Socket closed\")\n    msg.ParseFromString(buf)\n    return msg\n","sourceCodeStart":42,"sourceCodeEnd":66,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-rmi-trace/src/main/py/src/ghidratrace/util.py#L42-L66","documentation":"Intended to be raised as TraceRmiError by recv_delimited() when the length-prefix advertises a message size greater than MAX_MSG_LENGTH (1<<16 = 64 KiB), a sanity check against malicious/corrupt framing. IMPORTANT BUG: util.py raises 'TraceRmiError' but never imports or defines it, so if this line executes it throws NameError: name 'TraceRmiError' is not defined rather than the intended error.","triggerScenarios":"A corrupted/garbled length prefix decodes to a huge value; a peer using a different framing convention; memory corruption on the socket buffer; rarely a genuinely oversized message that bypassed the send-side guard due to the bug in 395.","commonSituations":"Protocol/version mismatch producing mis-framed bytes; noisy/unreliable link; debugging against a non-TraceRmi endpoint on the same port.","solutions":["Confirm both ends speak the same TraceRmi protocol/version.","Ensure you are connecting to a TraceRmi endpoint and not an unrelated service.","If developing, fix the latent bug by importing/defining TraceRmiError so this guard is actually usable."],"exampleFix":"// not a runtime fix per se — verify endpoint and version\n# before: client pointed at wrong port/service\n# after: connect to the Ghidra TraceRmi listening port and matching version","handlingStrategy":"validation","validationCode":"from ghidratrace.util import MAX_MSG_LENGTH\nif size > MAX_MSG_LENGTH:\n    raise ValueError(f'announced size {size} exceeds {MAX_MSG_LENGTH}; framing/endpoint mismatch')","typeGuard":null,"tryCatchPattern":"try:\n    msg = recv_delimited(s, proto, seq)\nexcept (ValueError, NameError):\n    # wrong endpoint or corrupt framing; reset connection\n    raise","preventionTips":["Connect only to genuine TraceRmi endpoints.","Match client/server protocol versions.","Fix the latent TraceRmiError import bug if you maintain util.py."],"tags":["network","trace-rmi","framing","size-limit","latent-bug"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}