{"record":{"id":"5dbe200e468f4a78","repo":"apache/cassandra","slug":"provided-frame-does-not-appear-to-be-lz4-compresse","errorCode":null,"errorMessage":"Provided frame does not appear to be LZ4 compressed","messagePattern":"Provided frame does not appear to be LZ4 compressed","errorType":"exception","errorClass":"org.apache.cassandra.transport.ProtocolException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/transport/Compressor.java","lineNumber":205,"sourceCode":"            catch (final Throwable e)\n            {\n                outputBuf.release();\n                throw e;\n            }\n            finally\n            {\n                uncompressed.release();\n            }\n        }\n\n        public Envelope decompress(Envelope compressed) throws IOException\n        {\n            try\n            {\n                byte[] input = CBUtil.readRawBytes(compressed.body);\n\n                if (input.length < INTEGER_BYTES)\n                    throw new ProtocolException(\"Provided frame does not appear to be LZ4 compressed\");\n\n                int uncompressedLength = ((input[0] & 0xFF) << 24)\n                                       | ((input[1] & 0xFF) << 16)\n                                       | ((input[2] & 0xFF) <<  8)\n                                       | ((input[3] & 0xFF));\n\n                validateUncompressedLength(uncompressedLength);\n                ByteBuf output = CBUtil.allocator.heapBuffer(uncompressedLength);\n\n                try\n                {\n                    int read = decompressor.decompress(input, INTEGER_BYTES, output.array(), output.arrayOffset(), uncompressedLength);\n                    if (read != input.length - INTEGER_BYTES)\n                        throw new IOException(\"Compressed lengths mismatch\");\n\n                    output.writerIndex(uncompressedLength);\n\n                    return compressed.with(output);","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/transport/Compressor.java#L187-L223","documentation":"LZ4-compressed native-protocol frames begin with a 4-byte big-endian uncompressed-length prefix followed by the LZ4 block. If the body is shorter than 4 bytes, the server cannot even read the prefix and throws this ProtocolException.","triggerScenarios":"Client negotiates LZ4 compression but sends a body shorter than 4 bytes — empty body, plaintext body, or truncated frame.","commonSituations":"Client incorrectly enables lz4 without implementing the 4-byte length prefix; proxies/truncation; custom drivers writing raw LZ4 without the header.","solutions":["Fix the client LZ4 framing: prefix each compressed body with the 4-byte big-endian uncompressed length.","Disable compression in client connection options to avoid LZ4 framing entirely.","Verify no intermediary truncates or rewrites the frame body.","Upgrade to an official driver that implements the LZ4 codec correctly."],"exampleFix":"// before: raw LZ4 block without length header\nbody = lz4.block.compress(plain);\n// after\nbyte[] compressed = lz4.block.compress(plain);\nbuf.writeInt(plain.length); // 4-byte uncompressed length prefix\nbuf.writeBytes(compressed);","handlingStrategy":"validation","validationCode":"if (body.length < 4) throw new IllegalStateException(\"LZ4 frame requires a 4-byte uncompressed-length prefix\");\nint uncompressedLength = ((body[0]&0xFF)<<24)|((body[1]&0xFF)<<16)|((body[2]&0xFF)<<8)|(body[3]&0xFF);","typeGuard":"boolean hasLz4Header(byte[] body) { return body != null && body.length >= 4; }","tryCatchPattern":"try { ... } catch (ProtocolException e) {\n    if (e.getMessage().contains(\"LZ4\")) { // disable compression or add 4-byte length prefix\n    }\n}","preventionTips":["Prefix every LZ4-compressed body with a 4-byte big-endian uncompressed length.","Round-trip test the LZ4 codec framing before deploying.","Use the official driver's built-in LZ4 support rather than custom framing.","Keep lz4 library versions consistent between build and runtime."],"tags":["compression","lz4","protocol","framing"],"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"}