{"record":{"id":"1d25f4b225f5dfaa","repo":"apache/cassandra","slug":"eof-after-limit-bytesread-bytes-out-of","errorCode":null,"errorMessage":"EOF after \" + (limit - bytesRead) + \" bytes out of \" + size","messagePattern":"EOF after \" \\+ \\(limit - bytesRead\\) \\+ \" bytes out of \" \\+ size","errorType":"exception","errorClass":"EOFException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/util/TrackedDataInputPlus.java","lineNumber":204,"sourceCode":"        int i = source.readUnsignedShort();\n        bytesRead += TypeSizes.SHORT_SIZE;\n        return i;\n    }\n\n    public int skipBytes(int n) throws IOException\n    {\n        int skipped = source.skipBytes(limit < 0 ? n : (int) Math.min(limit - bytesRead, n));\n        bytesRead += skipped;\n        return skipped;\n    }\n\n    @Inline\n    private void checkCanRead(int size) throws IOException\n    {\n        if (limit >= 0 && bytesRead + size > limit)\n        {\n            skipBytes((int) (limit - bytesRead));\n            throw new EOFException(\"EOF after \" + (limit - bytesRead) + \" bytes out of \" + size);\n        }\n    }\n}\n","sourceCodeStart":186,"sourceCodeEnd":208,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/util/TrackedDataInputPlus.java#L186-L208","documentation":"TrackedDataInputPlus wraps another input with a read limit. checkCanRead throws EOFException when a read of `size` bytes would exceed the remaining limit, after skipping to the limit boundary. It signals truncated data: fewer bytes were available than the reader requested.","triggerScenarios":"Any of readBoolean/readByte/readChar/readDouble/readFloat/readFully (and other size-checking reads) requesting more bytes than remain before the configured limit; e.g. reading a length-prefixed field that claims more bytes than the stream contains.","commonSituations":"Deserializing truncated messages or files; corrupt payloads whose embedded lengths exceed the actual frame size; protocol mismatches between writer and reader versions.","solutions":["Verify the upstream data source is complete and not truncated (check file size / frame length)","Validate embedded length prefixes against the available limit before reading","Check that writer and reader use compatible serialization versions","Catch EOFException and treat the payload as corrupt, logging the bytes read vs expected"],"exampleFix":"// before\ninput.readFully(buffer, 0, declaredLength); // may throw EOFException\n// after\nif (declaredLength > availableBytes()) throw new CorruptPayloadException(...);\ninput.readFully(buffer, 0, declaredLength);","handlingStrategy":"validation","validationCode":"if (limit >= 0 && needed > limit - bytesRead) throw new EOFException(\"truncated\"); // mirror the check before reading","typeGuard":"boolean canRead(TrackedDataInputPlus in, int n) { return in.available() >= n; }","tryCatchPattern":"try { in.readFully(buf, 0, n); } catch (EOFException e) { handleTruncated(e); }","preventionTips":["Validate length prefixes against frame limits before reading","Check file/frame sizes before deserializing","Keep serializer versions in sync between writer and reader","Treat EOFException during decode as data corruption, not a crash"],"tags":["eof","deserialization","truncated-data"],"backgroundTag":"file-read-failed","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"}