{"record":{"id":"0390fe1b742576e4","repo":"apache/cassandra","slug":"the-requested-position-exceeds-the-index-length-0390fe","errorCode":null,"errorMessage":"The requested position exceeds the index length","messagePattern":"The requested position exceeds the index length","errorType":"validation","errorClass":"IndexOutOfBoundsException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/io/sstable/format/big/BigTableKeyReader.java","lineNumber":184,"sourceCode":"\n    public RowIndexEntry rowIndexEntry() {\n        assert detailed;\n        return rowIndexEntry;\n    }\n\n    public FileHandle indexFile() {\n        return indexFile;\n    }\n\n    public long indexPosition()\n    {\n        return indexFileReader.getFilePointer();\n    }\n\n    public void indexPosition(long position) throws IOException\n    {\n        if (position > indexLength())\n            throw new IndexOutOfBoundsException(\"The requested position exceeds the index length\");\n        indexFileReader.seek(position);\n        key = null;\n        keyPosition = 0;\n        dataPosition = 0;\n        advance();\n    }\n\n    public long indexLength()\n    {\n        return indexFileReader.length();\n    }\n\n    @Override\n    public void reset() throws IOException\n    {\n        indexFileReader.seek(initialPosition);\n        key = null;\n        keyPosition = 0;","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/io/sstable/format/big/BigTableKeyReader.java#L166-L202","documentation":"BigTableKeyReader.indexPosition(long) seeks the Index.db reader to an arbitrary position. It validates the requested position against the index file length and throws IndexOutOfBoundsException('The requested position exceeds the index length') when the position lies past EOF, preventing a failed seek on a corrupt or stale index reference.","triggerScenarios":"A caller (e.g. KeyReader reset/seek, scrubber or verifier following an index entry) supplies a position greater than indexLength() — typically from a corrupted Index.db/Summary.db entry, a stale cached first/last index bound, or a file truncated concurrently.","commonSituations":"Corrupt or truncated Index.db after crash/disk failure; summary entries pointing beyond the index after an interrupted compaction; reading an SSTable whose file was replaced/truncated underneath a live reader.","solutions":["Run `nodetool scrub` on the table to rebuild/skip corrupt index structures.","Remove the suspect SSTable and run repair to restore good data.","Validate Index.db/Summary.db with `sstableverify`/`sstablemetadata` offline tools.","Check for disk-level truncation and hardware issues; verify file sizes against backup copies."],"exampleFix":"// before: blindly seeking into index\nkeyReader.indexPosition(entry.position); // throws if beyond EOF\n// after: guard the seek\nif (entry.position <= keyReader.indexLength())\n    keyReader.indexPosition(entry.position);\nelse\n    handleCorruptIndex(entry);","handlingStrategy":"validation","validationCode":"// Java: bounds-check before seek\nif (position >= 0 && position <= keyReader.indexLength())\n    keyReader.indexPosition(position);\nelse\n    logCorruptIndexEntry(position);","typeGuard":"boolean validIndexPos = (position >= 0 && position <= indexLength());","tryCatchPattern":"try {\n    keyReader.indexPosition(pos);\n} catch (IndexOutOfBoundsException e) {\n    logger.warn(\"Index position {} beyond index length {} — index corrupt\", pos, keyReader.indexLength());\n}","preventionTips":["Run verify/scrub regularly to detect index corruption early","Never read SSTables while they are being compacted away","Validate index/summary with offline sstable tools before heavy analysis jobs"],"tags":["sstable","index","bounds","corruption"],"backgroundTag":"index-out-of-bounds","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"}