{"record":{"id":"83bcd19cb4286f08","repo":"jdx/mise","slug":"recovery-content-failed-verification","errorCode":null,"errorMessage":"recovery content failed verification","messagePattern":"recovery content failed verification","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/history/recovery.rs","lineNumber":143,"sourceCode":"    Ok(())\n}\n\npub(super) fn read_blob(state_dir: &Path, blob: &Blob) -> Result<Vec<u8>> {\n    use base64::Engine;\n    validate_blob_id(&blob.sha256)?;\n    let bytes = match &blob.inline {\n        Some(inline) => base64::engine::general_purpose::STANDARD.decode(inline)?,\n        None => {\n            let path = super::journal::blobs_dir_in(state_dir).join(&blob.sha256);\n            let metadata = std::fs::symlink_metadata(&path)?;\n            if !metadata.is_file() || metadata.len() != blob.size {\n                bail!(\"invalid recovery content file\");\n            }\n            std::fs::read(path)?\n        }\n    };\n    if bytes.len() as u64 != blob.size || hex::encode(sha2::Sha256::digest(&bytes)) != blob.sha256 {\n        bail!(\"recovery content failed verification\");\n    }\n    Ok(bytes)\n}\n\nfn validate_snapshot(state_dir: &Path, snapshot: &PathSnapshot) -> Result<()> {\n    match snapshot {\n        PathSnapshot::File { content, .. } => {\n            read_blob(state_dir, content)?;\n        }\n        PathSnapshot::Dir {\n            files, links, dirs, ..\n        } => {\n            let mut seen = BTreeSet::new();\n            for relative in files\n                .iter()\n                .map(|f| &f.rel)\n                .chain(links.iter().map(|f| &f.rel))\n                .chain(dirs.iter().map(|f| &f.rel))","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/history/recovery.rs#L125-L161","documentation":"After decoding a blob (inline base64 or file), read_blob verifies both the byte length matches blob.size and that the SHA-256 hex digest of the bytes equals blob.sha256. A mismatch means the stored content is corrupt or was tampered with; recovery refuses to write unverified content back to disk.","triggerScenarios":"validate_snapshot or restore reading a blob whose decoded bytes hash to something other than blob.sha256, or whose length differs from blob.size: bit rot, partial/truncated reads, wrong content stored under the id, or edited inline base64.","commonSituations":"Disk corruption or failing drive; interrupted writes; a user manually edited or re-encoded a blob file; copying state_dir with a tool that altered files; hash recorded under a different hash algorithm.","solutions":["Delete the corrupt blob and re-create the snapshot so it is rewritten, then recover from the new snapshot","Restore the blob file from backup and verify `sha256sum` matches blob.sha256 before retrying","If corruption is systemic, check disk health (SMART) and migrate state_dir to healthy storage","Discard the affected operation with the history discard command if the preimage is not needed"],"exampleFix":"// before\n# blobs/<sha> hash no longer matches journal\nrecover_path(path, prior)?; // recovery content failed verification\n// after\nrm blobs_dir/<bad-sha>\n# re-checkpoint to regenerate, or restore from backup:\ncp backup/blobs/<sha> blobs_dir/<sha>\nsha256sum blobs_dir/<sha>   # must equal blob.sha256\nrecover_path(path, prior)?;","handlingStrategy":"validation","validationCode":"use sha2::{Digest, Sha256};\nfn blob_matches(bytes: &[u8], size: u64, sha256: &str) -> bool {\n    bytes.len() as u64 == size && hex::encode(Sha256::digest(bytes)) == sha256\n}","typeGuard":null,"tryCatchPattern":"match recover_path(dest, prior) {\n    Err(e) if e.to_string().contains(\"failed verification\") => {\n        eprintln!(\"blob corrupt (hash mismatch); regenerate snapshot or restore backup: {e}\");\n    }\n    other => other?,\n}","preventionTips":["Verify blob hashes after writing and before deleting sources","Monitor disk health; checksum mismatches often indicate failing storage","Treat blob files as immutable — never edit or re-encode them"],"tags":["sha256","checksum","corruption"],"backgroundTag":"checksum-mismatch","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}