{"record":{"id":"386c89fe6962070f","repo":"apache/cassandra","slug":"decompressed-lengths-mismatch","errorCode":null,"errorMessage":"Decompressed lengths mismatch","messagePattern":"Decompressed lengths mismatch","errorType":"exception","errorClass":"java.io.IOException","httpStatus":null,"severity":"critical","filePath":"src/java/org/apache/cassandra/io/compress/LZ4Compressor.java","lineNumber":163,"sourceCode":"\n        final int writtenLength;\n        try\n        {\n            writtenLength = decompressor.decompress(input,\n                                                    inputOffset + INTEGER_BYTES,\n                                                    inputLength - INTEGER_BYTES,\n                                                    output,\n                                                    outputOffset,\n                                                    decompressedLength);\n        }\n        catch (LZ4Exception e)\n        {\n            throw new IOException(e);\n        }\n\n        if (writtenLength != decompressedLength)\n        {\n            throw new IOException(\"Decompressed lengths mismatch\");\n        }\n\n        return decompressedLength;\n    }\n\n    public void uncompress(ByteBuffer input, ByteBuffer output) throws IOException\n    {\n        final int decompressedLength = (input.get() & 0xFF)\n                | ((input.get() & 0xFF) << 8)\n                | ((input.get() & 0xFF) << 16)\n                | ((input.get() & 0xFF) << 24);\n\n        try\n        {\n            int compressedLength = input.remaining();\n            decompressor.decompress(input, input.position(), input.remaining(), output, output.position(), decompressedLength);\n            input.position(input.position() + compressedLength);\n            output.position(output.position() + decompressedLength);","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/compress/LZ4Compressor.java#L145-L181","documentation":"LZ4Compressor.uncompress(byte[], int, int, byte[], int) decompresses a chunk and verifies that LZ4 produced exactly the number of bytes recorded in the chunk's stored decompressed length. If the frame decoder wrote fewer or more bytes than the header claims, the data is corrupt or misaligned, and an IOException with this message is thrown rather than returning silently truncated/extended output.","triggerScenarios":"Calling LZ4Compressor.uncompress on a byte buffer whose stored decompressed length does not match what LZ4 actually produced — i.e. corrupt, truncated, or bit-rotted SSTable chunk data, or data written by a different/incompatible LZ4 framing.","commonSituations":"Reading an SSTable damaged by hardware failure or an interrupted write; restoring backups copied incorrectly; reading data written by a mismatched Cassandra/LZ4 version.","solutions":["Verify and repair the affected SSTables (`nodetool scrub`, `nodetool verify`); restore the chunk from a backup or replica.","Rebuild the affected SSTables from other replicas by running a repair (`nodetool repair`).","Confirm the data was written with the same LZ4 compressor configuration (framing/level) as is being used to read it."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    compressor.uncompress(input, inputOffset, inputLen, output, outputOffset);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"Decompressed lengths mismatch\")) {\n        logger.warn(\"Corrupt chunk detected; failing over to replica\", e);\n        // mark sstable suspect / retry from replica\n    } else throw e;\n}","preventionTips":["Run periodic `nodetool verify` to detect corrupt chunks early.","Use ECC/RAID storage and verify backup integrity after copying.","Keep consistent compressor configuration across the cluster."],"tags":["lz4","decompression","data-corruption","io"],"backgroundTag":"checksum-mismatch","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}