{"record":{"id":"7fcba5e7f059b2fc","repo":"pola-rs/polars","slug":"offset-exceeds-usize-limits","errorCode":null,"errorMessage":"offset exceeds usize limits","messagePattern":"offset exceeds usize limits","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-core/src/frame/column/mod.rs","lineNumber":637,"sourceCode":"        self.slice(-(len as i64), len)\n    }\n    pub fn slice(&self, offset: i64, length: usize) -> Column {\n        match self {\n            Column::Series(s) => s.slice(offset, length).into(),\n            Column::Scalar(s) => {\n                let (_, length) = slice_offsets(offset, length, s.len());\n                s.resize(length).into()\n            },\n        }\n    }\n\n    pub fn split_at(&self, offset: i64) -> (Column, Column) {\n        match self {\n            Column::Scalar(c) => {\n                let len = c.len();\n                let offset = if offset < 0 {\n                    let offset_abs = usize::try_from(offset.strict_abs())\n                        .expect(\"offset exceeds usize limits\")\n                        .min(len);\n                    len - offset_abs\n                } else {\n                    usize::try_from(offset)\n                        .expect(\"offset exceeds usize limits\")\n                        .min(len)\n                };\n                (\n                    Column::Scalar(c.resize(offset)),\n                    Column::Scalar(c.resize(len - offset)),\n                )\n            },\n            Column::Series(_) => {\n                let (l, r) = self.as_materialized_series().split_at(offset);\n                (l.into(), r.into())\n            },\n        }\n    }","sourceCodeStart":619,"sourceCodeEnd":655,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-core/src/frame/column/mod.rs#L619-L655","documentation":"`Column::split_at(offset)` takes an i64 offset; for negative offsets the absolute value is converted to usize before being subtracted from the length. The conversion panics if the absolute value cannot be represented in usize, which on the negative branch happens only when offset == i64::MIN (whose absolute value overflows i64) or, on 32-bit targets, when |offset| > usize::MAX.","triggerScenarios":"Calling `column.split_at(i64::MIN)`; on 32-bit platforms calling `split_at` with a negative offset whose absolute value exceeds u32 range; any code path computing a split offset from untrusted input that can be i64::MIN.","commonSituations":"Generic numeric code passing sentinel values like i64::MIN as a 'beginning of column' marker; FFI/PyO3 boundaries where a Python int -9223372036854775808 is forwarded; 32-bit embedded/WASM builds using large negative offsets.","solutions":["Pass offsets within a safe range: for negative offsets use offset > i64::MIN (e.g. >= i64::MIN + 1), and keep |offset| within usize range on the target platform.","Validate the offset before calling: reject i64::MIN explicitly and clamp to the column length.","On 32-bit targets, pre-check `offset >= -(usize::MAX as i64)` before splitting."],"exampleFix":"// before\ncol.split_at(i64::MIN);\n\n// after\nlet offset = offset.max(i64::MIN + 1).min(col.len() as i64);\ncol.split_at(offset);","handlingStrategy":"validation","validationCode":"assert!(offset != i64::MIN, \"offset.abs() would overflow\");\nlet off = offset.clamp(-(col.len() as i64), col.len() as i64);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass i64::MIN as a split offset.","Clamp offsets to the column length before splitting.","Add explicit checks in generic wrappers around split_at."],"tags":["rust","polars","integer-overflow","split","value-out-of-range"],"backgroundTag":"value-out-of-range","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"}