{"record":{"id":"7aae5e56d82be54b","repo":"GitoxideLabs/gitoxide","slug":"enough-data-after-previous-check","errorCode":null,"errorMessage":"enough data after previous check","messagePattern":"enough data after previous check","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"gix-pack/src/data/file/init.rs","lineNumber":48,"sourceCode":"    T: crate::FileData,\n{\n    /// Instantiate a data file from `data` as assumed to be read or memory-mapped from `path`.\n    ///\n    /// This constructor leaves allocation limiting disabled, allowing allocations of any size dictated by pack data.\n    /// Call [`File::with_alloc_limit_bytes()`][crate::data::File::with_alloc_limit_bytes()] before decoding entries from untrusted input.\n    pub fn from_data(data: T, path: PathBuf, object_hash: gix_hash::Kind) -> Result<Self, data::header::decode::Error> {\n        let hash_len = object_hash.len_in_bytes();\n        let pack_len = data.len();\n        let id = gix_features::hash::crc32(path.as_os_str().to_string_lossy().as_bytes());\n        if pack_len < data::header::SIZE + hash_len {\n            return Err(data::header::decode::Error::Corrupt(format!(\n                \"Pack data of size {pack_len} is too small for even an empty pack with shortest hash\"\n            )));\n        }\n        let (kind, num_objects) = data::header::decode(\n            &data[..data::header::SIZE]\n                .try_into()\n                .expect(\"enough data after previous check\"),\n        )?;\n        Ok(Self {\n            data,\n            path,\n            id,\n            version: kind,\n            num_objects,\n            object_hash,\n            alloc_limit_bytes: None,\n        })\n    }\n\n    /// Configure the maximum size of a single allocation caused by user-controlled on-disk pack data.\n    ///\n    /// Use `None` to disable the limit, which is also the default.\n    ///\n    /// This is currently enforced when decoding pack entries and resolving delta chains.\n    /// Callers that allocate from pack metadata directly should consult [`File::alloc_limit_bytes()`][crate::data::File::alloc_limit_bytes]","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-pack/src/data/file/init.rs#L30-L66","documentation":"A `expect()` panic converting a slice of pack data to a fixed-size header array in `gix_pack::data::File::from_data`. The preceding length check guarantees the data is at least `header::SIZE` plus hash length bytes, so the `try_into` to `[u8; header::SIZE]` cannot fail. Failure indicates the guard above was bypassed or altered.","triggerScenarios":"Constructing a `gix_pack::data::File` via `from_data` with data shorter than the check threshold is impossible (it errors first); the panic only occurs if the size guard or `data::header::SIZE` constant changes inconsistently — i.e. a library bug.","commonSituations":"Opening packs smaller than the minimum size yields a normal error, not this panic; the panic is development/fuzzing-only territory.","solutions":["Update gix-pack","Validate pack files before opening (size and trailing hash)","Report upstream with the input that triggered it"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"let meta = std::fs::metadata(&pack_path)?;\nif meta.len() < (gix_pack::data::header::SIZE + 20 /* hash len */) as u64 {\n    return Err(\"pack file too small\".into());\n}","typeGuard":null,"tryCatchPattern":"let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| gix_pack::data::File::at(&path, id)));\nif r.is_err() { eprintln!(\"unexpected panic opening pack\"); }","preventionTips":["Check pack file size before opening (min header + trailer hash size)","Run pack verification on suspect packs","Keep gix-pack updated"],"tags":["rust","panic","internal-invariant","gix-pack","pack-initialization"],"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"}