{"record":{"id":"3037792ae6cb3ea0","repo":"aeron-io/aeron","slug":"malformed-command-303779","errorCode":"MALFORMED_COMMAND","errorMessage":"command={msgTypeId} too short: length={length}","messagePattern":"command=(.+?) too short: length=(.+?)","errorType":"error_code","errorClass":"ControlProtocolException","httpStatus":null,"severity":"error","filePath":"aeron-client/src/main/java/io/aeron/command/DestinationMessageFlyweight.java","lineNumber":155,"sourceCode":"     *\n     * @return length of the frame in bytes.\n     */\n    public int length()\n    {\n        return CHANNEL_OFFSET + lengthOfChannel;\n    }\n\n    /**\n     * Validate buffer length is long enough for message.\n     *\n     * @param msgTypeId type of message.\n     * @param length of message in bytes to validate.\n     */\n    public void validateLength(final int msgTypeId, final int length)\n    {\n        if (length < MINIMUM_LENGTH)\n        {\n            throw new ControlProtocolException(\n                MALFORMED_COMMAND, \"command=\" + msgTypeId + \" too short: length=\" + length);\n        }\n\n        if ((length - MINIMUM_LENGTH) < buffer.getInt(offset + CHANNEL_OFFSET))\n        {\n            throw new ControlProtocolException(\n                MALFORMED_COMMAND, \"command=\" + msgTypeId + \" too short for channel: length=\" + length);\n        }\n    }\n\n    /**\n     * Compute the length of the command message for a given channel length.\n     *\n     * @param channelLength to be appended to the header.\n     * @return the length of the command message for a given channel length.\n     */\n    public static int computeLength(final int channelLength)\n    {","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-client/src/main/java/io/aeron/command/DestinationMessageFlyweight.java#L137-L173","documentation":"The Aeron driver received a control-protocol command message whose total length is below the fixed MINIMUM_LENGTH for a destination (add/remove destination) message. DestinationMessageFlyweight.validateLength() is called by the driver on every incoming command; a too-short buffer means the message header is truncated or the wrong message type was sent, so the driver aborts processing with ControlProtocolException(MALFORMED_COMMAND).","triggerScenarios":"Sending an ADD_DESTINATION / REMOVE_DESTINATION (or client-side generated) control command whose encoded byte length is less than MINIMUM_LENGTH, e.g. a hand-crafted or corrupted command buffer on the driver control stream, or a client/driver version mismatch producing a shorter message layout.","commonSituations":"Custom or older Aeron client talking to a newer driver with different message layout; byte-level corruption or truncation of the control command buffer; buggy third-party tooling that fabricates driver control commands; manually multiplexed command streams where a length header is wrong.","solutions":["Verify the Aeron client and driver (MediaDriver/SampleConfiguration) use the same Aeron version; upgrade both together.","Check the code path that writes the destination command buffer to ensure it uses the flyweight's length computation instead of a hard-coded size.","Enable Aeron logging / driver event log to inspect the raw command that arrived and confirm the length field.","If writing a custom transport, ensure the full command frame (including channel string length and bytes) is written atomically without truncation."],"exampleFix":"// before\nbuffer.putByte(0, ADD_DESTINATION);\nbuffer.putInt(4, partialLength); // hard-coded, may undershoot MINIMUM_LENGTH\n// after\nDestinationMessageFlyweight msg = new DestinationMessageFlyweight(buffer);\nmsg.destination(ADD_DESTINATION, destinationUri, streamId);\nint length = DestinationMessageFlyweight.computeLength(destinationUri.length());\n// publish exactly `length` bytes","handlingStrategy":"validation","validationCode":"if (length < DestinationMessageFlyweight.MINIMUM_LENGTH) { throw new IllegalArgumentException(\"command too short: \" + length); }","typeGuard":null,"tryCatchPattern":"try { flyweight.validateLength(msgTypeId, length); } catch (ControlProtocolException e) { if (e.errorCode() == ControlProtocolException.MALFORMED_COMMAND) { log.error(\"Malformed control command, dropping\", e); } else { throw e; } }","preventionTips":["Keep Aeron client and driver on identical versions","Use flyweight APIs instead of manual byte encoding","Write command frames atomically without truncation","Check driver event logs when integrating custom command producers"],"tags":["aeron","control-protocol","malformed-command","driver"],"backgroundTag":"invalid-argument-format","analyzedSha":"6d60124e15e35c11b49ba2e3c2c2858a09a18803","analyzedAt":"2026-09-12T11:17:07.683Z","contentChangedAt":"2026-09-12T11:17:07.683Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}