{"record":{"id":"47a949853076bd58","repo":"aeron-io/aeron","slug":"malformed-command-47a949","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/StaticCounterMessageFlyweight.java","lineNumber":250,"sourceCode":"     * @return the length of the current message\n     */\n    public int length()\n    {\n        final int labelOffset = labelLengthOffset();\n        return labelOffset + SIZE_OF_INT + labelBufferLength();\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        final int labelOffset = labelLengthOffset();\n        if ((length - labelOffset) < SIZE_OF_INT)\n        {\n            throw new ControlProtocolException(\n                MALFORMED_COMMAND, \"command=\" + msgTypeId + \" too short for key: length=\" + length);\n        }\n\n        final int encodedLength = length();\n        if (length < encodedLength)\n        {\n            throw new ControlProtocolException(\n                MALFORMED_COMMAND,\n                \"command=\" + msgTypeId + \" too short for label: length=\" + length + \" encodedLength=\" + encodedLength);\n        }\n    }","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-client/src/main/java/io/aeron/command/StaticCounterMessageFlyweight.java#L232-L268","documentation":"StaticCounterMessageFlyweight.validateLength first checks the command meets the fixed MINIMUM_LENGTH (registration id + counters etc.). A shorter buffer means the fixed header fields cannot be decoded, so ControlProtocolException(MALFORMED_COMMAND) is thrown before variable parts (label/key) are examined.","triggerScenarios":"Publishing a STATIC_COUNTER command to the driver whose total length is below MINIMUM_LENGTH, e.g. truncating the buffer before write or a corrupted control message.","commonSituations":"Hand-rolled command encoding with wrong capacity, driver/client version skew changing the fixed layout, or corrupted Aeron Cnc file replayed from disk.","solutions":["Allocate and report at least StaticCounterMessageFlyweight.MINIMUM_LENGTH bytes for the command.","Prefer the AeronClient's high-level Counter APIs (Aeron.addCounter) instead of writing raw flyweights.","Align client and driver versions so the STATIC_COUNTER layout matches.","Call validateLength immediately after encoding to fail fast with a clear message."],"exampleFix":"// before\nUnsafeBuffer buf = new UnsafeBuffer(new byte[16]);\n// after\nUnsafeBuffer buf = new UnsafeBuffer(new byte[Math.max(StaticCounterMessageFlyweight.MINIMUM_LENGTH, computedLength)]);","handlingStrategy":"validation","validationCode":"if (buffer.capacity() < StaticCounterMessageFlyweight.MINIMUM_LENGTH) { throw new IllegalArgumentException(\"buffer too small for static counter command\"); }","typeGuard":null,"tryCatchPattern":"try { counter = aeron.addCounter(typeId, keyBuffer, keyOffset, keyLength, label); } catch (ControlProtocolException e) { /* handle MALFORMED_COMMAND */ }","preventionTips":["Use computeLength to size buffers","Prefer high-level Aeron.addCounter APIs","Match client/driver versions","Validate lengths before sending"],"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"}