{"record":{"id":"aace12aa2fa9a130","repo":"astrid-runtime/astrid","slug":"volume-seek-overflow","errorCode":null,"errorMessage":"volume seek overflow","messagePattern":"volume seek overflow","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/astrid-storage/src/volume.rs","lineNumber":419,"sourceCode":"                .map_err(|_| io::Error::other(\"volume write length overflow\"))?,\n            &mut &bytes[..],\n        )?;\n        Ok(bytes.len())\n    }\n\n    fn flush(&mut self) -> io::Result<()> {\n        self.volume.sync()\n    }\n}\n\nimpl Seek for VolumeFile {\n    fn seek(&mut self, position: SeekFrom) -> io::Result<u64> {\n        let next = match position {\n            SeekFrom::Start(offset) => i128::from(offset),\n            SeekFrom::Current(delta) => i128::from(self.cursor)\n                .checked_add(i128::from(delta))\n                .ok_or_else(|| {\n                    io::Error::new(io::ErrorKind::InvalidInput, \"volume seek overflow\")\n                })?,\n            SeekFrom::End(delta) => i128::from(self.volume.region_len(&self.region)?)\n                .checked_add(i128::from(delta))\n                .ok_or_else(|| {\n                    io::Error::new(io::ErrorKind::InvalidInput, \"volume seek overflow\")\n                })?,\n        };\n        self.cursor = u64::try_from(next)\n            .map_err(|_| io::Error::new(io::ErrorKind::InvalidInput, \"negative volume seek\"))?;\n        Ok(self.cursor)\n    }\n}\n\n/// Minimal metadata returned for a volume region.\n#[derive(Clone, Copy, Debug, PartialEq, Eq)]\npub struct VolumeMetadata {\n    length: u64,\n}","sourceCodeStart":401,"sourceCodeEnd":437,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-storage/src/volume.rs#L401-L437","documentation":"seek() computes the new cursor in i128 and returns InvalidInput ('volume seek overflow') when the arithmetic would overflow, specifically for SeekFrom::Current and SeekFrom::End additions that exceed the checked_add domain.","triggerScenarios":"SeekFrom::Current(delta) where cursor + delta overflows i64/i128 range; SeekFrom::End(delta) where region_len + delta overflows, e.g. extremely large delta values or u64::MAX offsets.","commonSituations":"Computing seek targets from unvalidated external offsets; using sentinel values like u64::MAX as deltas; corrupt metadata producing absurd region_len-derived targets.","solutions":["Validate offset/delta values before seeking and clamp to 0..=region_len","Use SeekFrom::Start with a bounded offset instead of large Current/End deltas","Compute the intended target in checked arithmetic in the caller first","Fix upstream code that passes sentinel/marker values (u64::MAX) as deltas"],"exampleFix":"// before\nlet pos = reader.seek(std::io::SeekFrom::Current(i64::MAX))?;\n// after\nlet target = (cursor as i128 + delta as i128).clamp(0, region_len as i128) as u64;\nlet pos = reader.seek(std::io::SeekFrom::Start(target))?;","handlingStrategy":"validation","validationCode":"fn safe_target(cursor: u64, delta: i64, region_len: u64) -> Option<u64> {\n    let t = cursor as i128 + delta as i128;\n    u64::try_from(t).ok().filter(|&t| t <= region_len)\n}","typeGuard":"fn seekable(offset: i128, region_len: u64) -> bool { (0..=region_len as i128).contains(&offset) }","tryCatchPattern":"match reader.seek(SeekFrom::Current(delta)) {\n    Err(e) if e.kind() == std::io::ErrorKind::InvalidInput => return Err(MyError::SeekOutOfBounds),\n    other => other?,\n}","preventionTips":["Clamp external offsets before seeking","Prefer SeekFrom::Start with computed clamped targets","Never use sentinel values (u64::MAX) as deltas","Compute seek math in i128 with checked ops in the caller"],"tags":["io","seek","overflow","validation"],"backgroundTag":"argument-out-of-range","analyzedSha":"affd8760f44190dbdfbec23403f4c4b642c33112","analyzedAt":"2026-09-09T21:28:12.402Z","contentChangedAt":"2026-09-09T21:28:12.402Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}