{"record":{"id":"14778bf03651fba2","repo":"astrid-runtime/astrid","slug":"blake3-evidence-collision-with-inconsistent-length","errorCode":null,"errorMessage":"BLAKE3 evidence collision with inconsistent lengths","messagePattern":"BLAKE3 evidence collision with inconsistent lengths","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/astrid-storage-chunker-evidence/src/metrics.rs","lineNumber":174,"sourceCode":"        })\n    }\n}\n\nfn insert_identity(\n    identities: &mut HashMap<[u8; 32], u64>,\n    bytes: &[u8],\n    unique_bytes: &mut u64,\n) -> Result<()> {\n    let length = u64::try_from(bytes.len())?;\n    let identity = *blake3::hash(bytes).as_bytes();\n    match identities.entry(identity) {\n        std::collections::hash_map::Entry::Vacant(entry) => {\n            entry.insert(length);\n            *unique_bytes = checked_add(*unique_bytes, length, \"unique byte count\")?;\n        },\n        std::collections::hash_map::Entry::Occupied(entry) => {\n            if *entry.get() != length {\n                bail!(\"BLAKE3 evidence collision with inconsistent lengths\");\n            }\n        },\n    }\n    Ok(())\n}\n\nfn deduplication(logical_bytes: u64, retained_bytes: u64) -> Result<Deduplication> {\n    if retained_bytes > logical_bytes {\n        bail!(\"retained bytes exceed logical bytes\");\n    }\n    let saved_bytes = logical_bytes\n        .checked_sub(retained_bytes)\n        .ok_or_else(|| anyhow::anyhow!(\"retained bytes exceed logical bytes\"))?;\n    Ok(Deduplication {\n        retained_bytes,\n        saved_bytes,\n        retained_basis_points: basis_points(retained_bytes, logical_bytes)?,\n        saved_basis_points: basis_points(saved_bytes, logical_bytes)?,","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/astrid-runtime/astrid/blob/affd8760f44190dbdfbec23403f4c4b642c33112/crates/astrid-storage-chunker-evidence/src/metrics.rs#L156-L192","documentation":"insert_identity tracks unique content identities with their byte lengths and accumulates unique byte counts. If an identity already exists with a different recorded length, the map is inconsistent (or a hash collision occurred), so it bails rather than corrupting dedup statistics.","triggerScenarios":"add_record inserting a chunk/representation identity whose stored length differs from the current byte-slice length — from corrupted evidence, mutated record bytes after hashing, or an injected collision.","commonSituations":"Stale or truncated metrics persisted across runs; concurrent mutation of records between hashing and insertion; adversarial fuzz inputs.","solutions":["Re-hash and compare the record's bytes against the original to detect corruption.","Rebuild the evidence/metrics state from source data.","Investigate for true hash collision only if inputs are verified distinct yet same identity."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if let Some(prev) = unique.get(&id) { assert_eq!(*prev, bytes.len() as u64, \"length drift for identity\"); }","typeGuard":null,"tryCatchPattern":"match metrics.add_chunk_record(bytes, n) {\n    Err(e) if e.to_string().contains(\"inconsistent lengths\") => return Err(anyhow!(\"corrupted evidence: {e}\")),\n    other => other,\n}","preventionTips":["Keep record bytes immutable between hashing and insertion","Avoid mixing records from different measurement runs","Validate persisted evidence before loading"],"tags":["hashing","blake3","deduplication","integrity"],"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"}