{"record":{"id":"326992329f613e8a","repo":"astrid-runtime/astrid","slug":"blake3-evidence-collision-with-inconsistent-file-l","errorCode":null,"errorMessage":"BLAKE3 evidence collision with inconsistent file lengths","messagePattern":"BLAKE3 evidence collision with inconsistent file lengths","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/astrid-storage-chunker-evidence/src/metrics.rs","lineNumber":77,"sourceCode":"    cdc_chunk_lengths: Vec<(u64, u64)>,\n}\n\nimpl Accumulator {\n    pub fn add_file(&mut self, bytes: &[u8]) -> Result<()> {\n        let length = u64::try_from(bytes.len())?;\n        self.add_file_identity(length, *blake3::hash(bytes).as_bytes())\n    }\n\n    pub fn add_file_identity(&mut self, length: u64, identity: [u8; 32]) -> Result<()> {\n        self.files = checked_add(self.files, 1, \"file count\")?;\n        self.logical_bytes = checked_add(self.logical_bytes, length, \"logical byte count\")?;\n        match self.whole_files.entry(identity) {\n            std::collections::hash_map::Entry::Vacant(entry) => {\n                entry.insert(length);\n            },\n            std::collections::hash_map::Entry::Occupied(entry) => {\n                if *entry.get() != length {\n                    bail!(\"BLAKE3 evidence collision with inconsistent file lengths\");\n                }\n            },\n        }\n        Ok(())\n    }\n\n    pub fn add_whole_record(&mut self, bytes: &[u8]) -> Result<()> {\n        self.add_record(bytes, 1, false)\n    }\n\n    pub fn add_chunk_record(&mut self, bytes: &[u8], logical_chunks: u64) -> Result<()> {\n        self.add_record(bytes, logical_chunks, true)\n    }\n\n    fn add_record(&mut self, bytes: &[u8], logical_chunks: u64, cdc: bool) -> Result<()> {\n        if logical_chunks == 0 {\n            bail!(\"a representation record must cover at least one logical chunk\");\n        }","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-storage-chunker-evidence/src/metrics.rs#L59-L95","documentation":"add_file_identity registers each whole-file BLAKE3 hash mapped to its byte length. If two different files hash to the same identity but have different lengths, this invariant is broken and the library bails, because BLAKE3 collisions with differing lengths indicate corrupted evidence or a hashing bug.","triggerScenarios":"Calling add_file_identity (via measure or add_file) with a file whose BLAKE3 identity was already recorded under a different length — practically only via manually tampered identity data, truncated/mutated evidence stores, or a deliberately injected collision.","commonSituations":"Corrupted on-disk evidence files; hand-edited metrics inputs; fuzzing or adversarial tests feeding crafted collisions.","solutions":["Verify the input file integrity (re-hash the source content and compare).","Delete and regenerate the evidence/metrics state, since persisted identities are inconsistent.","If reproducible with distinct files, report it — a genuine BLAKE3 collision with different lengths is a cryptographic anomaly."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if let Some(prev) = known_lengths.get(&identity) {\n    if *prev != file_len { return Err(anyhow!(\"inconsistent identity {}\", identity)); }\n}","typeGuard":null,"tryCatchPattern":"match add_file_identity(&mut m, identity, len) {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"collision\") => regenerate_evidence(),\n    Err(e) => return Err(e),\n}","preventionTips":["Never hand-edit persisted identity maps","Re-hash source files after any external modification","Treat identity collisions with differing lengths as data corruption"],"tags":["hashing","blake3","integrity","collision"],"backgroundTag":"checksum-mismatch","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"}