{"record":{"id":"557a54b8949bcc7e","repo":"apache/cassandra","slug":"not-enough-bytes-to-read-an-utf8-serialized-string-557a54","errorCode":null,"errorMessage":"Not enough bytes to read an UTF8 serialized string preceded by its 4 bytes length","messagePattern":"Not enough bytes to read an UTF8 serialized string preceded by its 4 bytes length","errorType":"exception","errorClass":"org.apache.cassandra.transport.ProtocolException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/transport/CBUtil.java","lineNumber":214,"sourceCode":"     * Returns the ecoding size of a US-ASCII string. It does not work if containing any char > 0x007F (127)\n     * @param str satisfies {@link org.apache.cassandra.db.marshal.AsciiType}\n     *             i.e. seven-bit ASCII, a.k.a. ISO646-US\n     */\n    public static int sizeOfAsciiString(String str)\n    {\n        return 2 + str.length();\n    }\n\n    public static String readLongString(ByteBuf cb)\n    {\n        try\n        {\n            int length = cb.readInt();\n            return readString(cb, length);\n        }\n        catch (IndexOutOfBoundsException e)\n        {\n            throw new ProtocolException(\"Not enough bytes to read an UTF8 serialized string preceded by its 4 bytes length\");\n        }\n    }\n\n    public static void writeLongString(String str, ByteBuf cb)\n    {\n        int length = encodedUTF8Length(str);\n        cb.writeInt(length);\n        ByteBufUtil.reserveAndWriteUtf8(cb, str, length);\n    }\n\n    public static int sizeOfLongString(String str)\n    {\n        return 4 + encodedUTF8Length(str);\n    }\n\n    public static byte[] readBytes(ByteBuf cb)\n    {\n        try","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/transport/CBUtil.java#L196-L232","documentation":"CBUtil.readLongString(ByteBuf) reads a 4-byte int length then that many UTF-8 bytes. When fewer bytes remain than the declared length (IndexOutOfBoundsException), it throws ProtocolException describing the long-string framing. Same family as the short-string guard but for 4-byte-length fields like query strings.","triggerScenarios":"A long string field (e.g., CQL query string) declares a length larger than the remaining readable bytes — truncated frame, bogus length prefix, or desynced parsing.","commonSituations":"Very large queries cut off by intermediaries; corrupt frame from a buggy driver; protocol version mismatch during handshake.","solutions":["Check intermediaries (proxies, LBs, MTU/SSL offload) for truncation of large frames","Ensure the client native protocol version matches the server's expectations","Reconnect to resync and reproduce with driver debug logging","Validate the declared 4-byte length against frame size when crafting custom clients"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { ... } catch (ProtocolException e) { if (e.getMessage().contains(\"preceded by its 4 bytes length\")) { reconnectSession(); } else throw e; }","preventionTips":["Avoid intermediaries that buffer-limit large queries; raise native_transport_max_frame_size if needed","Match driver and server protocol versions","Enable driver frame logging when debugging custom clients"],"tags":["cql-protocol","truncated-frame","framing"],"backgroundTag":"unexpected-response-shape","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}