{"record":{"id":"ac64dc156cc9431e","repo":"apache/cassandra","slug":"invalid-checksum-headerchecksum-datachecksu","errorCode":null,"errorMessage":"Invalid checksum: <headerChecksum> != <dataChecksum>","messagePattern":"Invalid checksum: <headerChecksum> != <dataChecksum>","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/util/CompressedFrameDataInputPlus.java","lineNumber":82,"sourceCode":"        int length = compressed.getShort();\n\n        boolean decompress = length >= 0;\n        if (!decompress)\n            length = -1 - length;\n\n        compressed.clear();\n        compressed.limit(length);\n        while (compressed.hasRemaining())\n        {\n            if (channel.read(compressed) < 0)\n                throw new EOFException(\"Incomplete file: header stipulated \" + length + \" bytes but found only \" + compressed.position());\n        }\n        compressed.flip();\n        this.checksum.update(compressed);\n        compressed.flip();\n        long dataChecksum = checksum.getValue();\n        if (headerChecksum != dataChecksum)\n            throw new IOException(\"Invalid checksum: \" + headerChecksum + \" != \" + dataChecksum);\n\n        buffer.clear();\n        if (decompress) compressor.uncompress(compressed, buffer);\n        else buffer.put(compressed);\n        buffer.flip();\n    }\n\n    public static <T> T read(File file, IVersionedSerializer<T> serializer) throws IOException\n    {\n        try (CompressedFrameDataInputPlus in = new CompressedFrameDataInputPlus(DEFAULT_FRAME_SIZE, file.newReadChannel(), ZstdCompressor.getOrCreate(DEFAULT_COMPRESSION_LEVEL), Crc.crc32()))\n        {\n            int version = in.readUnsignedVInt32();\n            return serializer.deserialize(in, version);\n        }\n    }\n\n    public static <T> T readOne(File file, UnversionedSerializer<T> serializer) throws IOException\n    {","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/util/CompressedFrameDataInputPlus.java#L64-L100","documentation":"Each frame stores a CRC32 in its header computed over the compressed payload. reBuffer() recomputes the checksum of the bytes just read and throws this IOException when the stored and computed checksums differ, indicating the frame data was corrupted on disk or in transit.","triggerScenarios":"Reading a CompressedFrame file whose payload bytes were altered after write: bit rot, faulty disk, corrupted transfer, or reading bytes from the wrong offset (e.g. file overwritten concurrently or a different file version than the reader expects).","commonSituations":"Hardware-level corruption on an SSTable-adjacent metadata file; a file written with a different framing/checksum algorithm being read by this reader; concurrent modification of the file while it is being read.","solutions":["Restore the file from a known-good backup or regenerate it; the frame content is not recoverable via this reader.","Run filesystem/disk health checks (fsck, SMART) on the storage holding the file.","Ensure no process writes to the file while it is being read (check for concurrent writers).","Verify the reader and writer use the same CompressedFrameDataOutputPlus/InputPlus format version."],"exampleFix":"// before\nConfig cfg = CompressedFrameDataInputPlus.readOne(file, serializer);\n// after\nConfig cfg;\ntry {\n    cfg = CompressedFrameDataInputPlus.readOne(file, serializer);\n} catch (IOException e) {\n    if (e.getMessage().startsWith(\"Invalid checksum\")) {\n        logger.error(\"Corrupt file {} detected\", file, e);\n        markCorrupted(file);\n        cfg = defaultConfig();\n    } else throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { ...read... }\ncatch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Invalid checksum\")) handleCorruption(file);\n    else throw e;\n}","preventionTips":["Use ECC/storage with checksumming (ZFS) for data directories","Never modify files after they are written","Keep reader and writer format versions in sync","Run nodetool verify periodically"],"tags":["io","checksum","file-corruption","crc"],"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"}