{"record":{"id":"6d6bca827e393745","repo":"apache/cassandra","slug":"eof-after-skipped-bytes-out-of-n","errorCode":null,"errorMessage":"EOF after <skipped> bytes out of <n>","messagePattern":"EOF after <skipped> bytes out of <n>","errorType":"exception","errorClass":"EOFException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/util/DataInputPlus.java","lineNumber":126,"sourceCode":"                     | (readByte() & 0xffL);\n            case 8: return readLong();\n            default: throw new IllegalArgumentException();\n        }\n    }\n\n    /**\n     * Always skips the requested number of bytes, unless EOF is reached\n     *\n     * @param n number of bytes to skip\n     * @return number of bytes skipped\n     */\n    public int skipBytes(int n) throws IOException;\n\n    public default void skipBytesFully(int n) throws IOException\n    {\n        int skipped = skipBytes(n);\n        if (skipped != n)\n            throw new EOFException(\"EOF after \" + skipped + \" bytes out of \" + n);\n    }\n\n    @Override\n    default byte readByte() throws IOException\n    {\n        return (byte) readUnsignedByte();\n    }\n\n    @Override\n    default boolean readBoolean() throws IOException\n    {\n        return readUnsignedByte() != 0;\n    }\n\n    @Override\n    default short readShort() throws IOException\n    {\n        int ch1 = readUnsignedByte();","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/util/DataInputPlus.java#L108-L144","documentation":"DataInputPlus.skipBytesFully(n) is a strict skip: it calls skipBytes(n) and throws EOFException if fewer bytes could be skipped than requested, guaranteeing callers that the stream is positioned exactly n bytes past the start and that the underlying source still had the data.","triggerScenarios":"Skipping a row body / cell value / serialized field whose declared length exceeds the remaining bytes in the stream — typically reading a truncated or corrupted SSTable row, commit log segment, or handoff file; or a length field read incorrectly due to format mismatch.","commonSituations":"Streaming/compacting a truncated SSTable; replaying a partially flushed commit log; reading inter-node message or hinted-handoff data cut short by a crash; deserializing with a serializer whose layout doesn't match the written one.","solutions":["Treat the file/segment as truncated: stop reading at the last known-good offset (e.g. use CommitLogDescriptor/segment checksums to find the safe end).","Restore or repair the data file from replica/backup if the corrupted source must be recovered.","Verify reader and writer use the same serialization format/version; a mismatched schema can make lengths bogus.","Catch EOFException in the streaming path and skip the damaged record rather than failing the whole operation."],"exampleFix":"// before\nin.skipBytesFully(rowBodySize);\n// after\ntry {\n    in.skipBytesFully(rowBodySize);\n} catch (EOFException e) {\n    logger.warn(\"Truncated record, aborting read at {}\", in); \n    throw e; // or stop processing this segment\n}\n","handlingStrategy":"try-catch","validationCode":"// check declared length against remaining bytes when the input exposes it\n// e.g. if (declaredLength > input.availableBytes()) throw before skipping","typeGuard":null,"tryCatchPattern":"try { input.skipBytesFully(n); }\ncatch (EOFException e) { abortSegment(e); /* stop at last good offset */ }","preventionTips":["Validate length fields against file size before skipping","Use checksummed inputs (ChecksummedDataInput) to detect truncation early","Don't read files still being written","Handle partial commit-log/SSTable segments as normal crash recovery"],"tags":["io","eof","serialization","truncation"],"backgroundTag":"unexpected-eof","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"}