{"record":{"id":"5f88d665d3002b47","repo":"apache/cassandra","slug":"unable-to-seek-to-position-d-in-s-d-bytes-in-5f88d6","errorCode":null,"errorMessage":"Unable to seek to position %d in %s (%d bytes) in read-only mode","messagePattern":"Unable to seek to position (.+?) in (.+?) \\((.+?) bytes\\) in read-only mode","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/util/RandomAccessReader.java","lineNumber":234,"sourceCode":"\n    @Override\n    public void seek(long newPosition)\n    {\n        if (newPosition < 0)\n            throw new IllegalArgumentException(\"new position should not be negative\");\n\n        if (buffer == null)\n            throw new IllegalStateException(\"Attempted to seek in a closed RAR\");\n\n        long bufferOffset = bufferHolderOffset;\n        if (newPosition >= bufferOffset && newPosition < bufferOffset + buffer.limit())\n        {\n            buffer.position((int) (newPosition - bufferOffset));\n            return;\n        }\n\n        if (newPosition > length())\n            throw new IllegalArgumentException(String.format(\"Unable to seek to position %d in %s (%d bytes) in read-only mode\",\n                                                         newPosition, getPath(), length()));\n        reBufferAt(newPosition);\n    }\n\n    @Override\n    public int skipBytes(int n) throws IOException\n    {\n        if (n <= 0)\n            return 0;\n        if (buffer == null)\n            throw new IOException(\"Attempted skipBytes() on a closed RAR\");\n        long current = current();\n        long newPosition = Math.min(current + n, length());\n        n = (int)(newPosition - current);\n        seek(newPosition);\n        return n;\n    }\n","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/util/RandomAccessReader.java#L216-L252","documentation":"RandomAccessReader is read-only over a fixed file length, so seek() rejects any position greater than length() with a formatted IllegalArgumentException naming the position, file path, and total size. Unlike a RandomAccessFile, you cannot seek past EOF to extend a read-only view.","triggerScenarios":"Calling seek(pos) where pos > length() — from readSyncMarker scanning near end-of-file with bogus marker offsets, keyIterator/keyReader using corrupt index offsets, or caller-supplied offsets from a corrupted/truncated file whose declared length exceeds the actual file.","commonSituations":"Corrupted sstable segments where stored offsets point past EOF; reading a file that was truncated after its length metadata was written; off-by-one on file size (using size+1) or wrong units (bytes vs. chunks).","solutions":["Clamp the target: seek(Math.min(offset, reader.length())) or skip the read when offset >= length()","Validate offsets read from file metadata against the actual file size before seeking","Run sstable verify/scrub — offsets past EOF usually indicate corruption","Check that you opened the correct/complete file (not a partially-copied one) so length() matches expectations"],"exampleFix":"// before\nreader.seek(commitLogSegmentMarkerOffset); // may exceed length\n// after\nif (markerOffset >= 0 && markerOffset < reader.length()) {\n    reader.seek(markerOffset);\n} else {\n    break; // corrupted or truncated file, stop scanning\n}","handlingStrategy":"validation","validationCode":"if (offset >= 0 && offset < reader.length()) reader.seek(offset); else stopReading();","typeGuard":"boolean inBounds = offset >= 0 && offset < reader.length();","tryCatchPattern":"try { reader.seek(offset); } catch (IllegalArgumentException e) { throw new CorruptFileException(e.getMessage()); }","preventionTips":["Bounds-check offsets against length() before seek","Distrust stored offsets in files that may be truncated","Verify sstables after unclean shutdown"],"tags":["io","randomaccessreader","validation"],"backgroundTag":"value-out-of-range","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"}