{"record":{"id":"5169f4433667d20a","repo":"aeron-io/aeron","slug":"malformed-command-5169f4","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/RemoveMessageFlyweight.java","lineNumber":112,"sourceCode":"     *\n     * @return length of the message in bytes.\n     */\n    public static int length()\n    {\n        return LENGTH + SIZE_OF_LONG;\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}\n","sourceCodeStart":94,"sourceCodeEnd":117,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-client/src/main/java/io/aeron/command/RemoveMessageFlyweight.java#L94-L117","documentation":"Aeron's driver control-protocol flyweights validate that an incoming command message carries at least MINIMUM_LENGTH bytes before fields are decoded. When RemoveMessageFlyweight.validateLength sees a length below that fixed minimum, the command is malformed and a ControlProtocolException with MALFORMED_COMMAND is thrown. This protects the client/driver from reading garbage or out-of-bounds fields from a truncated buffer.","triggerScenarios":"Sending a remove-registration (RICK/REMOVE) command whose buffer length is below MINIMUM_LENGTH, e.g. a truncated or miswritten publication to the driver's control channel, or passing a wrong length to the flyweight.","commonSituations":"Buffer under-allocation when assembling commands by hand, protocol version mismatches between client and media driver, corrupted shared-memory (cnc) files, or third-party code writing to the control stream with a wrong length header.","solutions":["Ensure the command buffer is allocated at least RemoveMessageFlyweight.MINIMUM_LENGTH bytes and that the length passed to the driver matches the encoded message.","Rebuild client and driver from the same Aeron version so the control-protocol layout matches.","If assembling commands manually, call validateLength before putting the message on the control queue to catch the bug at the source.","Verify the term/cnc buffers are not corrupted; restart the driver to recreate them."],"exampleFix":"// before\nUnsafeBuffer buf = new UnsafeBuffer(new byte[8]);\nremoveMessageFlyweight.setRegistrationId(0, regId);\n// after\nUnsafeBuffer buf = new UnsafeBuffer(new byte[RemoveMessageFlyweight.MINIMUM_LENGTH]);\nremoveMessageFlyweight.setRegistrationId(0, regId);\nremoveMessageFlyweight.validateLength(msgTypeId, buf.capacity());","handlingStrategy":"validation","validationCode":"if (buffer.capacity() < RemoveMessageFlyweight.MINIMUM_LENGTH) { throw new IllegalArgumentException(\"buffer too small for remove command\"); }","typeGuard":null,"tryCatchPattern":"try { flyweight.validateLength(msgTypeId, length); driverProxy.removePublication(regId); } catch (ControlProtocolException e) { if (e.errorCode() == ControlProtocolEvents.MALFORMED_COMMAND) { log.error(\"malformed command\", e); } }","preventionTips":["Always size command buffers from the flyweight's MINIMUM_LENGTH or computeLength","Keep client and driver on the same Aeron version","Call validateLength immediately after encoding","Never hand-edit the command ring buffer"],"tags":["aeron","control-protocol","malformed-command"],"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"}