GitoxideLabs/gitoxide · warning
parser validation
Error message
parser validation
What it means
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.
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.
Example fix
// before let refs = gix_ref::pack::packed_refs(buf, gix_hash::Kind::Sha1)?; // repo is Sha256 -> panic later // after let refs = gix_ref::pack::packed_refs(buf, repo.object_hash())?; // match the repo's hash kind
Defensive patterns
Strategy: validation
Validate before calling
// confirm hash kind matches the packed-refs source before parsing assert_eq!(repo.object_hash(), gix_hash::Kind::Sha1); // or detect kind first let refs = gix_ref::file::pack::Refs::from_packed_refs(buf, repo.object_hash())?;
Try / catch
// panics are not catchable in Rust; avoid by matching hash kinds and validating input let refs = gix_ref::file::pack::Refs::from_packed_refs(buf, detected_kind).map_err(|e| ...)?;
Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- this one only happens on iteration creation
- parse validation
- prior validation
- peeked value exists
- name retrieval configured
AI-assisted analysis of GitoxideLabs/gitoxide@e73179060b (2026-09-08).
Data as JSON: /api/errors/9cc5291cfee819c8.
Report an issue: GitHub.
Appendix: source
Thrown at gix-ref/src/raw.rs:55
impl From<loose::Reference> for Reference {
fn from(value: loose::Reference) -> Self {
Reference {
name: value.name,
target: value.target,
peeled: None,
}
}
}
impl<'p> From<packed::Reference<'p>> for Reference {
fn from(value: packed::Reference<'p>) -> Self {
Reference {
name: value.name.into(),
target: Target::Object(value.target()),
peeled: value
.object
.map(|hex| ObjectId::from_hex(hex).expect("parser validation")),
}
}
}
}
mod access {
use gix_object::bstr::ByteSlice;
use crate::{FullNameRef, Namespace, Target, raw::Reference};
impl Reference {
/// Returns the kind of reference based on its target
pub fn kind(&self) -> crate::Kind {
self.target.kind()
}
/// Return the full validated name of the reference, with the given namespace stripped if possible.
///View on GitHub (pinned to e73179060b)