{"record":{"id":"e11bf3f3ad98348c","repo":"pola-rs/polars","slug":"invalid-seek-to-a-negative-or-overflowing-position","errorCode":null,"errorMessage":"invalid seek to a negative or overflowing position","messagePattern":"invalid seek to a negative or overflowing position","errorType":"error_code","errorClass":"std::io::Error","httpStatus":null,"severity":"error","filePath":"crates/polars-utils/src/chunked_bytes_cursor.rs","lineNumber":129,"sourceCode":"impl<'a, T> std::io::Seek for FixedSizeChunkedBytesCursor<'a, T> {\n    fn seek(&mut self, pos: std::io::SeekFrom) -> std::io::Result<u64> {\n        // Mostly copied from io::Cursor::seek().\n        use std::io::SeekFrom;\n\n        let (base_pos, offset) = match pos {\n            SeekFrom::Start(n) => {\n                self.position = usize::try_from(n).unwrap().min(self.total_size);\n                return Ok(self.position as u64);\n            },\n            SeekFrom::End(n) => (self.total_size as u64, n),\n            SeekFrom::Current(n) => (self.position as u64, n),\n        };\n        match base_pos.checked_add_signed(offset) {\n            Some(n) => {\n                self.position = usize::try_from(n).unwrap();\n                Ok(self.position as u64)\n            },\n            None => Err(std::io::Error::new(\n                std::io::ErrorKind::InvalidInput,\n                \"invalid seek to a negative or overflowing position\",\n            )),\n        }\n    }\n}\n","sourceCodeStart":111,"sourceCodeEnd":136,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-utils/src/chunked_bytes_cursor.rs#L111-L136","documentation":"ChunkedBytesCursor::seek returns an io::Error of kind InvalidInput when the requested seek position (base position plus signed offset) is negative or overflows usize. The cursor cannot represent such a position, so the seek fails instead of wrapping. It surfaces as a standard std::io::Error, typically wrapped in a Polars error by higher layers.","triggerScenarios":"Calling Seek::seek with SeekFrom::Start larger than usize::MAX, a SeekFrom::Current/End offset that moves before position 0, or a target beyond usize addressable range on a ChunkedBytesCursor.","commonSituations":"Corrupted Parquet/IPC metadata containing out-of-range offsets; code computing byte offsets with underflow; reading truncated files where stored offsets exceed actual buffer length combined with End-relative seeks.","solutions":["Verify the file is not truncated or corrupted; re-download/regenerate the source file","Check computed offsets before seeking (use checked arithmetic on offsets)","Ensure SeekFrom::Start values fit within u64/usize bounds and Current/End offsets don't go negative"],"exampleFix":"// before\nlet off = row_group_offset - computed_offset; // may underflow\ncursor.seek(SeekFrom::Current(off))?;\n// after\nlet off = row_group_offset.checked_sub(computed_offset).ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, \"negative offset\"))?;\ncursor.seek(SeekFrom::Current(off))?;","handlingStrategy":"try-catch","validationCode":"// Rust: bounds-check before seeking\nfn safe_seek(cursor: &mut ChunkedBytesCursor, pos: u64) -> std::io::Result<()> {\n    if pos > usize::MAX as u64 { return Err(std::io::Error::new(std::io::ErrorKind::InvalidInput, \"position out of range\")); }\n    cursor.seek(std::io::SeekFrom::Start(pos))\n}","typeGuard":"fn seekable(pos: u64) -> bool { pos <= usize::MAX as u64 }","tryCatchPattern":"match cursor.seek(SeekFrom::Current(off)) {\n    Ok(p) => { /* use p */ },\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidInput => { /* negative/overflowing seek: recover or abort */ },\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Use checked arithmetic for all offset computations","Validate file metadata offsets against actual file size before seeking","Treat truncated/corrupt files as suspect when InvalidInput seeks occur"],"tags":["rust","io","seek","cursor"],"backgroundTag":"invalid-argument-value","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}