{"record":{"id":"9cc5291cfee819c8","repo":"GitoxideLabs/gitoxide","slug":"parser-validation","errorCode":null,"errorMessage":"parser validation","messagePattern":"parser validation","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"gix-ref/src/raw.rs","lineNumber":55,"sourceCode":"\n    impl From<loose::Reference> for Reference {\n        fn from(value: loose::Reference) -> Self {\n            Reference {\n                name: value.name,\n                target: value.target,\n                peeled: None,\n            }\n        }\n    }\n\n    impl<'p> From<packed::Reference<'p>> for Reference {\n        fn from(value: packed::Reference<'p>) -> Self {\n            Reference {\n                name: value.name.into(),\n                target: Target::Object(value.target()),\n                peeled: value\n                    .object\n                    .map(|hex| ObjectId::from_hex(hex).expect(\"parser validation\")),\n            }\n        }\n    }\n}\n\nmod access {\n    use gix_object::bstr::ByteSlice;\n\n    use crate::{FullNameRef, Namespace, Target, raw::Reference};\n\n    impl Reference {\n        /// Returns the kind of reference based on its target\n        pub fn kind(&self) -> crate::Kind {\n            self.target.kind()\n        }\n\n        /// Return the full validated name of the reference, with the given namespace stripped if possible.\n        ///","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-ref/src/raw.rs#L37-L73","documentation":"This is a Rust `expect()` panic in the `From<packed::Reference>` conversion for `gix_ref::raw::Reference`. Packed-refs files store object ids as fixed-width hex; the pack parser (`packed::Reference`) already validated the hex digits and length during decoding, so `ObjectId::from_hex` is expected to succeed. If it panics, the hex slice coming out of the packed-refs decoder did not match the repository's hash kind, meaning an invariant in the pack decoding layer was broken.","triggerScenarios":"Iterating a packed-refs file (`gix_ref::pack::Refs` / packed buffer iteration) whose decoder yielded a hex id inconsistent with the configured `gix_hash::Kind` (e.g. wrong hash kind passed when opening a packed-refs file, or a corrupted/malformed packed-refs binary buffer parsed by an older/incompatible parser).","commonSituations":"Repositories created with SHA-256 but opened with SHA-256 disabled or vice versa; hand-edited or truncated `.git/packed-refs` files; mixing packed-refs produced by a different git implementation.","solutions":["Ensure the `gix_hash::Kind` used to open the repository matches the one the packed-refs file was written with (SHA-1 vs SHA-256).","Regenerate or repair `packed-refs` by running `git pack-refs --all` with a stock git client.","Validate/inspect the packed-refs file bytes for corruption before parsing.","If it happens with valid files, report it upstream with the packed-refs sample — it is a decoder invariant bug."],"exampleFix":"// before\nlet refs = gix_ref::pack::packed_refs(buf, gix_hash::Kind::Sha1)?; // repo is Sha256 -> panic later\n// after\nlet refs = gix_ref::pack::packed_refs(buf, repo.object_hash())?; // match the repo's hash kind","handlingStrategy":"validation","validationCode":"// confirm hash kind matches the packed-refs source before parsing\nassert_eq!(repo.object_hash(), gix_hash::Kind::Sha1); // or detect kind first\nlet refs = gix_ref::file::pack::Refs::from_packed_refs(buf, repo.object_hash())?;","typeGuard":null,"tryCatchPattern":"// panics are not catchable in Rust; avoid by matching hash kinds and validating input\nlet refs = gix_ref::file::pack::Refs::from_packed_refs(buf, detected_kind).map_err(|e| ...)?;","preventionTips":["Always pass the repository's own gix_hash::Kind to packed-refs parsing","Don't mix SHA-1 and SHA-256 repositories/data","Validate packed-refs files (git fsck / git pack-refs) before low-level parsing"],"tags":["rust","panic","packed-refs","hex-decoding"],"backgroundTag":"internal-invariant-violation","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"}