{"record":{"id":"046157a1cc9cf5ee","repo":"apache/cassandra","slug":"invalid-ip-address-d-d-d-d-while-deserializi","errorCode":null,"errorMessage":"Invalid IP address (%d.%d.%d.%d) while deserializing inet address","messagePattern":"Invalid IP address \\((.+?)\\.(.+?)\\.(.+?)\\.(.+?)\\) while deserializing inet address","errorType":"exception","errorClass":"org.apache.cassandra.transport.ProtocolException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/transport/CBUtil.java","lineNumber":688,"sourceCode":"            s.add(readString(cb));\n            l[i] = readBoundValueAsByteArray(cb, protocolVersion);\n        }\n        return Pair.create(s, l);\n    }\n\n    public static InetSocketAddress readInet(ByteBuf cb)\n    {\n        int addrSize = cb.readByte() & 0xFF;\n        byte[] address = new byte[addrSize];\n        cb.readBytes(address);\n        int port = cb.readInt();\n        try\n        {\n            return new InetSocketAddress(InetAddress.getByAddress(address), port);\n        }\n        catch (UnknownHostException e)\n        {\n            throw new ProtocolException(String.format(\"Invalid IP address (%d.%d.%d.%d) while deserializing inet address\", address[0], address[1], address[2], address[3]));\n        }\n    }\n\n    public static void writeInet(InetSocketAddress inet, ByteBuf cb)\n    {\n        byte[] address = inet.getAddress().getAddress();\n\n        cb.writeByte(address.length);\n        cb.writeBytes(address);\n        cb.writeInt(inet.getPort());\n    }\n\n    public static int sizeOfInet(InetSocketAddress inet)\n    {\n        byte[] address = inet.getAddress().getAddress();\n        return 1 + address.length + 4;\n    }\n","sourceCodeStart":670,"sourceCodeEnd":706,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/transport/CBUtil.java#L670-L706","documentation":"Thrown when the native protocol driver sends an inet address whose byte array cannot be converted to an InetAddress. CBUtil deserializes the address bytes from the frame; if the byte length is not a valid address size (4 or 16 bytes), InetAddress.getByAddress throws UnknownHostException and this ProtocolException is raised, which closes the connection.","triggerScenarios":"A client sends an OPTIONS/STARTUP or other frame containing an inet value whose address byte array length is neither 4 nor 16 bytes (malformed serialization, buggy driver, corrupted frame).","commonSituations":"Custom or hand-rolled CQL binary protocol clients; middleware/proxies rewriting frames; fuzzer-generated or corrupted traffic; drivers built for a different protocol version.","solutions":["Fix the client to serialize the inet address as exactly 4 bytes (IPv4) or 16 bytes (IPv6) followed by the 4-byte port.","Check the driver version matches the server's supported protocol versions (negotiate via STARTUP).","Inspect traffic with a proxy (e.g. tcpdump or a CQL proxy) to verify the frame's inet field length byte.","Capture the offending frame and reproduce with a minimal client to confirm serialization is correct."],"exampleFix":"// before: address serialized with wrong length\nbyte[] address = hostname.getBytes();\n// after: serialize raw IP bytes + port\nbyte[] address = InetAddress.getByName(\"10.0.0.1\").getAddress(); // 4 or 16 bytes\nbuffer.writeInt(address.length);\nbuffer.writeBytes(address);\nbuffer.writeInt(port);","handlingStrategy":"validation","validationCode":"byte[] address = inet.getAddress().getAddress();\nif (address.length != 4 && address.length != 16)\n    throw new IllegalArgumentException(\"inet address must be 4 or 16 bytes, got \" + address.length);","typeGuard":"boolean isValidInetAddressBytes(byte[] a) { return a != null && (a.length == 4 || a.length == 16); }","tryCatchPattern":"try { ... } catch (com.datastax.driver.core.exceptions.NoNodeAvailableException | ProtocolException e) {\n    log.error(\"Malformed inet in frame, closing connection\", e);\n}","preventionTips":["Use an official Cassandra driver instead of hand-rolled protocol serialization.","Always derive address bytes from InetAddress.getAddress(), never from string/hostname bytes.","Add integration tests that serialize/deserialize both IPv4 and IPv6 inet values.","Log the frame hex dump before connecting to spot length errors early."],"tags":["network","protocol","deserialization","cql-native-protocol"],"backgroundTag":"invalid-argument-format","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"}