{"record":{"id":"baaa474e3d963f75","repo":"apache/shardingsphere","slug":"invalid-batch-parameter-length-for-tag-d-d","errorCode":null,"errorMessage":"Invalid batch parameter length for tag %d: %d","messagePattern":"Invalid batch parameter length for tag (.+?): (.+?)","errorType":"exception","errorClass":"FirebirdProtocolException","httpStatus":null,"severity":"error","filePath":"proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/batch/FirebirdBatchCreateCommandExecutor.java","lineNumber":164,"sourceCode":"            }\n            // return new BatchParameters(version, bufferSize, recordCounts, multiError, blobPolicy);\n            return new BatchParameters(version, bufferSize, recordCounts, multiError);\n        }\n        \n        private static long getBufferSize(final int requestedBufferSize) {\n            long result = Integer.toUnsignedLong(requestedBufferSize);\n            return 0L == result ? MAX_BUFFER_SIZE : Math.min(result, MAX_BUFFER_SIZE);\n        }\n        \n        private static void ensureClumpletHeaderReadable(final ByteBuf reader) {\n            if (reader.readableBytes() < 1 + WIDE_CLUMPLET_LENGTH_SIZE) {\n                throw new FirebirdProtocolException(\"Invalid batch parameters buffer\");\n            }\n        }\n        \n        private static void ensureClumpletValueReadable(final ByteBuf reader, final int tag, final int valueLength) {\n            if (valueLength < 0 || valueLength > reader.readableBytes()) {\n                throw new FirebirdProtocolException(\"Invalid batch parameter length for tag %d: %d\", tag, valueLength);\n            }\n        }\n        \n        private static int readIntegerValue(final ByteBuf reader, final int tag, final int valueLength) {\n            if (INTEGER_VALUE_LENGTH != valueLength) {\n                throw new FirebirdProtocolException(\"Invalid batch parameter integer length for tag %d: %d\", tag, valueLength);\n            }\n            return reader.readIntLE();\n        }\n    }\n}\n","sourceCodeStart":146,"sourceCodeEnd":176,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/batch/FirebirdBatchCreateCommandExecutor.java#L146-L176","documentation":"FirebirdProtocolException from ensureClumpletValueReadable: a batch parameter clumplet declares a value length that is negative or larger than the bytes actually remaining in the buffer. The declared length cannot be satisfied, so the clumplet stream is corrupt.","triggerScenarios":"BatchParameters.parse() reads valueLength = reader.readIntLE() and checks valueLength < 0 || valueLength > reader.readableBytes(); a client-sent length field pointing past the end of the buffer (or a sign-bit-set length read as negative) triggers the throw with the offending tag and length in the message.","commonSituations":"big-endian vs little-endian confusion when hand-writing the length (proxy reads readIntLE); length includes the header itself instead of only the value; buffer truncated mid-clumplet.","solutions":["Write clumplet value lengths as 4-byte LITTLE-ENDIAN integers counting only the value bytes.","Ensure total buffer length equals the sum of all clumplet headers plus declared value lengths.","Compare the generated bytes against a capture of a working Firebird client doing the same operation."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (SQLException e) {\n    if (e.getMessage().contains(\"Invalid batch parameter length\")) { throw new IllegalStateException(\"client clumplet length bug (LE/overrun)\", e); }\n    throw e;\n}","preventionTips":["Write clumplet lengths little-endian, counting value bytes only.","Cross-check total buffer size against the sum of clumplets."],"tags":["firebird","batch","clumplet","protocol","malformed-packet"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}