{"record":{"id":"4ed086b3c50fa100","repo":"jdx/mise","slug":"cached-oci-layer-size-mismatch","errorCode":null,"errorMessage":"cached OCI layer size mismatch","messagePattern":"cached OCI layer size mismatch","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/oci/layer/cache.rs","lineNumber":126,"sourceCode":"    Ok(hex_encode(&hash.finalize()))\n}\n\nfn field(hash: &mut Sha256, bytes: &[u8]) {\n    hash.update((bytes.len() as u64).to_le_bytes());\n    hash.update(bytes);\n}\n\nfn read_cached_layer(record_path: &Path, cache_dir: &Path) -> Result<Option<LayerBlob>> {\n    let record = match std::fs::read(record_path) {\n        Ok(bytes) => bytes,\n        Err(err) if err.kind() == std::io::ErrorKind::NotFound => return Ok(None),\n        Err(err) => return Err(err.into()),\n    };\n    let record: CachedLayer = serde_json::from_slice(&record)?;\n    crate::oci::layout::validate_sha256_digest(&record.digest)?;\n    crate::oci::layout::validate_sha256_digest(&record.diff_id)?;\n    let bytes = std::fs::read(cache_dir.join(record.digest.trim_start_matches(\"sha256:\")))?;\n    eyre::ensure!(\n        bytes.len() as u64 == record.size,\n        \"cached OCI layer size mismatch\"\n    );\n    let digest = format!(\"sha256:{}\", hex_encode(&Sha256::digest(&bytes)));\n    eyre::ensure!(digest == record.digest, \"cached OCI layer digest mismatch\");\n    let mut decoder = flate2::read::GzDecoder::new(bytes.as_slice());\n    let mut hash = Sha256::new();\n    let mut buffer = [0; 64 * 1024];\n    loop {\n        let n = decoder.read(&mut buffer)?;\n        if n == 0 {\n            break;\n        }\n        hash.update(&buffer[..n]);\n    }\n    let diff_id = format!(\"sha256:{}\", hex_encode(&hash.finalize()));\n    eyre::ensure!(\n        diff_id == record.diff_id,","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/oci/layer/cache.rs#L108-L144","documentation":"When mise rebuilds an OCI image from a cached layer (read_cached_layer in src/oci/layer/cache.rs:126), it verifies the cached blob file matches the size recorded in the cache metadata. This error means the layer blob on disk has a byte length different from the `size` field of the CachedLayer record — i.e. the cache is corrupt, truncated, or was written by a different/incomplete download.","triggerScenarios":"Calling read_cached_layer (via build_cached_tool_layer) where the file at cache_dir/<digest> exists but its length != record.size. Typical causes: an interrupted cache write, disk corruption or truncation, manual edits/deletions inside the OCI cache directory, or a stale record pointing at an overwritten blob.","commonSituations":"A tool cache populated by a killed process or full disk; sharing an OCI cache directory between machines/versions with rsync that skipped or truncated files; manually pruning files in the cache; filesystem corruption after a crash.","solutions":["Clear the OCI layer cache so it is repopulated: delete the cache directory mise used (e.g. under ~/.cache/mise OCI cache) and re-run the build/push.","Re-run the operation that populated the cache while online so the layer is re-downloaded and re-verified.","Check disk health/free space — truncation often indicates a full disk or fs corruption; fix that before re-caching.","If you copy cache dirs, use a checksum-verifying method (rsync --checksum) instead of plain copies."],"exampleFix":"// shell fix\n# before: build fails with size mismatch\nrm -rf ~/.cache/mise/oci\n# after: cache rebuilt\nmise build-push ...  # re-downloads and revalidates layers","handlingStrategy":"fallback","validationCode":"let meta = std::fs::metadata(blob_path)?;\nif meta.len() != expected_size {\n  eprintln!(\"cache entry invalid; clearing\");\n  std::fs::remove_file(blob_path)?;\n}","typeGuard":null,"tryCatchPattern":"match read_cached_layer(...) {\n  Err(e) if e.to_string().contains(\"size mismatch\") => {\n    invalidate_cache_entry(digest);\n    fetch_layer_fresh(digest)\n  }\n  other => other,\n}","preventionTips":["Don't interrupt cache-populating operations; ensure adequate disk space","Never hand-edit or prune files inside the OCI cache directory","Use checksum-verified copies (rsync --checksum) when sharing caches"],"tags":["oci","cache","integrity","integrity-check"],"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"}