{"record":{"id":"cf2c1d184f167118","repo":"apache/cassandra","slug":"incomplete-file-header-stipulated-length-bytes","errorCode":null,"errorMessage":"Incomplete file: header stipulated <length> bytes but found only <position>","messagePattern":"Incomplete file: header stipulated <length> bytes but found only <position>","errorType":"exception","errorClass":"EOFException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/util/CompressedFrameDataInputPlus.java","lineNumber":75,"sourceCode":"    protected void reBuffer() throws IOException\n    {\n        compressed.position(0);\n        compressed.limit(SIZE_OF_HEADER);\n        while (channel.read(compressed) >= 0 && compressed.hasRemaining());\n        compressed.flip();\n        long headerChecksum = compressed.getLong();\n        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        {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/util/CompressedFrameDataInputPlus.java#L57-L93","documentation":"CompressedFrameDataInputPlus reads length-prefixed, checksummed, Zstd-compressed frames from a channel. reBuffer() reads a frame header specifying the payload length; if the underlying channel hits EOF before that many bytes are read, this EOFException is thrown, meaning the file is truncated or corrupted.","triggerScenarios":"Calling CompressedFrameDataInputPlus.read/readOne/readList (or streaming from it) on a file that was truncated mid-frame — e.g. an incomplete flush during crash, a partial copy/rsync of the file, or reading a file still being written.","commonSituations":"Reading CompressedFrame files produced by CompressedFrameDataOutputPlus after an aborted write; copying SSTable-adjacent metadata files without completion markers; disk-full during write truncating the tail of the file; network filesystem serving stale file size metadata.","solutions":["Verify the file is complete and was fully written — re-copy or regenerate it from the source node/backup.","Check file size on disk vs the size at write time; if truncated, restore from backup or rebuild the data.","Confirm the writer finished successfully (no crash/disk-full); re-run the write if the producer is under your control.","Catch EOFException and treat the file as unreadable, falling back to reconstruction rather than retrying."],"exampleFix":"// before\nMyMeta meta = CompressedFrameDataInputPlus.readOne(file, serializer);\n// after\nMyMeta meta;\ntry {\n    meta = CompressedFrameDataInputPlus.readOne(file, serializer);\n} catch (EOFException e) {\n    logger.warn(\"Truncated file {}, rebuilding\", file, e);\n    meta = rebuildMeta();\n}","handlingStrategy":"try-catch","validationCode":"// before reading\nif (!java.nio.file.Files.exists(file.toPath()) || java.nio.file.Files.size(file.toPath()) == 0)\n    throw new IOException(\"File missing or empty: \" + file);","typeGuard":null,"tryCatchPattern":"try { return CompressedFrameDataInputPlus.readOne(file, serializer); }\ncatch (EOFException e) { logger.warn(\"Truncated file {}\", file); return fallback(); }","preventionTips":["Only read these files after the writer has fully flushed and closed them","Copy SSTable component sets atomically (all files together)","Monitor for disk-full during writes","Verify file sizes against expected sizes after transfer"],"tags":["io","eof","file-corruption","compression"],"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"}