{"record":{"id":"9e43944950c52261","repo":"NationalSecurityAgency/ghidra","slug":"cannot-send-tracermi-message-with-excessive-length","errorCode":null,"errorMessage":"Cannot send TraceRmi message with excessive length","messagePattern":"Cannot send TraceRmi message with excessive length","errorType":"exception","errorClass":"TraceRmiError","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-rmi-trace/src/main/java/ghidra/app/plugin/core/debug/service/tracermi/TraceRmiHandler.java","lineNumber":424,"sourceCode":"\tprotected RootMessage receive() {\n\t\ttry {\n\t\t\t// May return null when the socket is closed normally\n\t\t\treturn recvDelimited(in);\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\t// Also return null for abnormal closure\n\t\t\tMsg.error(this, \"Cannot read packet: \" + e);\n\t\t\tflushXReqQueue(e);\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tprotected static void sendDelimited(OutputStream out, RootMessage msg, long dbgSeq)\n\t\t\tthrows IOException {\n\t\tByteBuffer buf = ByteBuffer.allocate(Integer.BYTES);\n\t\tint len = msg.getSerializedSize();\n\t\tif (len > MAX_MSG_LENGTH) {\n\t\t\tthrow new TraceRmiError(\"Cannot send TraceRmi message with excessive length\");\n\t\t}\n\t\tbuf.putInt(len);\n\t\tout.write(buf.array());\n\t\tmsg.writeTo(out);\n\t\tout.flush();\n\t}\n\n\tprotected static byte[] recvAll(InputStream in, int len) throws IOException {\n\t\tbyte[] buf = new byte[len];\n\t\tint total = 0;\n\t\twhile (total < len) {\n\t\t\tint l = in.read(buf, total, len - total);\n\t\t\tif (l <= 0) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\ttotal += l;\n\t\t}\n\t\treturn buf;","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-rmi-trace/src/main/java/ghidra/app/plugin/core/debug/service/tracermi/TraceRmiHandler.java#L406-L442","documentation":"Thrown by TraceRmiHandler.sendDelimited when a RootMessage being serialized exceeds MAX_MSG_LENGTH (1 << 16 = 64 KiB). The length-prefix framing protocol caps message size to avoid unbounded memory allocation, so an oversized message is refused before it is written to the socket. This is a hard protocol limit defined at TraceRmiHandler.java:79.","triggerScenarios":"A request or reply that serializes to more than 64 KiB: large memory dumps embedded in a single message, a very large value/byte-array payload, a bulk object snapshot, or a request carrying many keys/values at once.","commonSituations":"Backend writing a large memory region's full contents in one putBytes/setValue call; sending a big register bank or large byte array without chunking; protobuf message with oversized repeated fields.","solutions":["Chunk large payloads into multiple messages each under 64 KiB (e.g. write memory in <= 60 KiB blocks).","Reduce the size of a single message by paginating object/value lists or streaming snapshots in pieces.","If a legitimate single value exceeds the cap, restructure the protocol usage so no one field carries the full payload.","Confirm you are not accidentally serializing redundant/debug data into the message."],"exampleFix":"# before: one giant write\nconn.proxy.put_bytes(start, huge_blob)  # >64KiB\n\n# after: chunked writes\nCHUNK = 32 * 1024\noff = start\nfor i in range(0, len(huge_blob), CHUNK):\n    conn.proxy.put_bytes(off, huge_blob[i:i+CHUNK])\n    off += CHUNK","handlingStrategy":"validation","validationCode":"RootMessage msg = req.build();\nint len = msg.getSerializedSize();\nif (len > TraceRmiHandler.MAX_MSG_LENGTH) {\n    // split payload / chunk the operation\n    throw new IllegalStateException(\"message too large: \" + len);\n}","typeGuard":null,"tryCatchPattern":"try {\n    TraceRmiHandler.sendDelimited(out, msg, dbgSeq);\n} catch (TraceRmiError e) {\n    // payload exceeds 64 KiB; chunk and resend\n}","preventionTips":["Cap each memory/value payload well under 64 KiB and chunk large transfers.","Paginate repeated/bulk fields in a single message.","Check msg.getSerializedSize() before serializing large requests."],"tags":["trace-rmi","message-size","protocol","network"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}