{"record":{"id":"5d825afee486afb4","repo":"GitoxideLabs/gitoxide","slug":"in-bound-distance-of-deltas","errorCode":null,"errorMessage":"in-bound distance of deltas","messagePattern":"in-bound distance of deltas","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-pack/src/data/entry/mod.rs","lineNumber":46,"sourceCode":"    }\n}\n\n/// Access\nimpl Entry {\n    /// Compute the pack offset to the base entry of the object represented by this entry, or\n    /// return `None` if the distance would underflow or is invalid.\n    pub fn checked_base_pack_offset(&self, distance: u64) -> Option<data::Offset> {\n        Header::verified_base_pack_offset(self.pack_offset(), distance)\n    }\n\n    /// Compute the pack offset to the base entry of the object represented by this entry.\n    ///\n    /// # Panics\n    ///\n    /// Panics if the `distance` will cause an underflow or is invalid.\n    pub fn base_pack_offset(&self, distance: u64) -> data::Offset {\n        self.checked_base_pack_offset(distance)\n            .expect(\"in-bound distance of deltas\")\n    }\n    /// The pack offset at which this entry starts\n    pub fn pack_offset(&self) -> data::Offset {\n        self.data_offset - self.header_size() as u64\n    }\n    /// The amount of bytes used to describe this entry in the pack.\n    ///\n    /// For entries decoded from pack data this returns the actual encoded header length, including\n    /// non-canonical overlong size encodings accepted by Git. This is the length to use for offset\n    /// reconstruction because the header starts at [`Self::pack_offset()`] and the compressed data\n    /// starts at [`Entry::data_offset`].\n    ///\n    /// If [`Entry::encoded_header_size`] is `0`, the actual encoded length is unknown and this falls\n    /// back to [`Header::size()`], which computes the canonical serialized length from the decoded\n    /// header and decompressed size.\n    pub fn header_size(&self) -> usize {\n        if self.encoded_header_size == 0 {\n            self.header.size(self.decompressed_size)","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-pack/src/data/entry/mod.rs#L28-L64","documentation":"`Entry::base_pack_offset(distance)` computes the delta base's pack offset by subtracting `distance` from the entry offset. The method is documented to panic if the distance causes an underflow or is invalid; the error means the caller supplied a delta base distance that reaches before the start of the pack, indicating corrupt delta data.","triggerScenarios":"Calling `base_pack_offset(distance)` on an OFS_DELTA/REF_DELTA entry with a distance larger than the entry's own pack offset, e.g. from a corrupted pack or a wrongly parsed header.","commonSituations":"Traversing corrupted packs, manually constructed delta entries, or code that mis-computes base distances when reimplementing pack parsing.","solutions":["Validate `distance <= entry.pack_offset()` before calling, or use `checked_base_pack_offset(distance)` which returns Option","Re-verify / re-download the pack if corruption is suspected (`git fsck`)","Switch to `checked_base_pack_offset` and handle None explicitly"],"exampleFix":"// before\nlet base = entry.base_pack_offset(distance); // panics on bad distance\n// after\nlet base = entry.checked_base_pack_offset(distance)\n    .ok_or_else(|| anyhow::anyhow!(\"invalid delta base distance {distance}\"))?;","handlingStrategy":"validation","validationCode":"if distance > entry.pack_offset() { return Err(anyhow!(\"delta base distance {} exceeds entry offset\", distance)); }","typeGuard":null,"tryCatchPattern":"// prefer the checked API over the panicking one\nlet base = entry.checked_base_pack_offset(distance)\n    .ok_or_else(|| anyhow!(\"invalid delta base distance\"))?;","preventionTips":["Always use `checked_base_pack_offset` in library-style code","Validate delta headers from untrusted packs before offset math","Run pack verification on downloaded packs before delta resolution"],"tags":["rust","panic","pack","delta","corruption"],"backgroundTag":"argument-out-of-range","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}