{"record":{"id":"4f9c1b5d5bbbbee3","repo":"apache/cassandra","slug":"invalid-uncompressed-frame-length-d-it-must-be-n","errorCode":null,"errorMessage":"Invalid uncompressed frame length %d; it must be non-negative and no greater than native_transport_max_frame_size (%d bytes)","messagePattern":"Invalid uncompressed frame length (.+?); it must be non-negative and no greater than native_transport_max_frame_size \\((.+?) bytes\\)","errorType":"exception","errorClass":"org.apache.cassandra.transport.ProtocolException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/transport/Compressor.java","lineNumber":48,"sourceCode":"import io.netty.buffer.ByteBuf;\n\npublic interface Compressor\n{\n    public Envelope compress(Envelope uncompressed) throws IOException;\n    public Envelope decompress(Envelope compressed) throws IOException;\n\n    /**\n     * Validates the uncompressed length declared in the header of a compressed frame before it is used to size a\n     * destination buffer.\n     *\n     * @param uncompressedLength the expected uncompressed length\n     * @throws ProtocolException when the uncompressed is negative, zero, or exceeds {@code native_transport_max_frame_size}\n     */\n    static void validateUncompressedLength(int uncompressedLength)\n    {\n        int maxFrameSize = DatabaseDescriptor.getNativeTransportMaxFrameSize();\n        if (uncompressedLength < 0 || uncompressedLength > maxFrameSize)\n            throw new ProtocolException(String.format(\"Invalid uncompressed frame length %d; it must be non-negative and \" +\n                                                      \"no greater than native_transport_max_frame_size (%d bytes)\",\n                                                      uncompressedLength, maxFrameSize));\n    }\n\n    /*\n     * TODO: We can probably do more efficient, like by avoiding copy.\n     * Also, we don't reuse ICompressor because the API doesn't expose enough.\n     */\n    public static class SnappyCompressor implements Compressor\n    {\n        public static final SnappyCompressor instance;\n        static\n        {\n            SnappyCompressor i;\n            try\n            {\n                i = new SnappyCompressor();\n            }","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/transport/Compressor.java#L30-L66","documentation":"When a client negotiates frame compression, each compressed frame starts with the uncompressed length. Compressor.validateUncompressedLength rejects values that are negative or exceed native_transport_max_frame_size, since decompressing them would be unsafe or exceed server limits.","triggerScenarios":"A compressed frame whose leading 4-byte uncompressed-length field is negative (bad LZ4/Snappy framing) or larger than native_transport_max_frame_size configured on the server.","commonSituations":"Client configured with compression but a frame size limit larger than the server's; a client writing a garbage/uninitialized length header; buggy third-party compression wrappers.","solutions":["Set native_transport_max_frame_size in cassandra.yaml to a value >= the client's maximum frame size (or lower the client's frame size).","Fix the client to write the correct uncompressed length in the frame header before the compressed payload.","Disable compression in the client connection options to isolate whether the compression framing is the problem.","Upgrade the client driver to a version with correct LZ4/Snappy framing."],"exampleFix":"// before (client): oversized frames\ncassandra.yaml: native_transport_max_frame_size_in_mb: 16 vs client frame of 64MB\n// after: align limits\ncassandra.yaml: native_transport_max_frame_size_in_mb: 64\nclient: { frameWidth: 64 * 1024 * 1024, compression: 'lz4' }","handlingStrategy":"validation","validationCode":"int max = serverConfig.getNativeTransportMaxFrameSize();\nif (uncompressedLength < 0 || uncompressedLength > max)\n    fail(\"frame exceeds server native_transport_max_frame_size: \" + uncompressedLength);","typeGuard":"boolean isFrameLengthSafe(int len, int maxFrameSize) { return len >= 0 && len <= maxFrameSize; }","tryCatchPattern":"try { session.execute(query); } catch (ProtocolException e) {\n    if (e.getMessage().contains(\"native_transport_max_frame_size\")) {\n        // reduce client frame size or raise server config\n    }\n}","preventionTips":["Keep client max frame size <= server's native_transport_max_frame_size.","Always write the uncompressed length header for compressed frames.","Verify compression codec framing with a round-trip unit test.","Check cassandra.yaml after upgrades, where defaults can change."],"tags":["compression","protocol","frame-size","config"],"backgroundTag":"value-out-of-range","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"}