{"record":{"id":"43c5243a0e298c8a","repo":"jdx/mise","slug":"remote-cache-blob-pack-returned-an-unrequested-dig","errorCode":null,"errorMessage":"remote cache blob pack returned an unrequested digest","messagePattern":"remote cache blob pack returned an unrequested digest","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/mise-cache-core/src/lib.rs","lineNumber":823,"sourceCode":"        let (algorithm, mut hasher) = match algorithm[0] {\n            1 => (\n                \"blake3\",\n                BlobPackHasher::Blake3(Box::new(blake3::Hasher::new())),\n            ),\n            2 => (\"sha256\", BlobPackHasher::Sha256(sha2::Sha256::new())),\n            _ => bail!(\"remote cache blob pack has an invalid digest algorithm\"),\n        };\n        let mut hash = [0_u8; 32];\n        reader.read_exact(&mut hash).await?;\n        let mut size = [0_u8; 8];\n        reader.read_exact(&mut size).await?;\n        let digest = CacheDigest {\n            algorithm: algorithm.into(),\n            hash: hex::encode(hash),\n            size: u64::from_be_bytes(size),\n        };\n        if !requested.contains(&digest) {\n            bail!(\"remote cache blob pack returned an unrequested digest\");\n        }\n        if !seen.insert(digest.clone()) {\n            bail!(\"remote cache blob pack returned a duplicate digest\");\n        }\n        framed_bytes = framed_bytes\n            .checked_add(BLOB_PACK_HEADER_BYTES)\n            .and_then(|bytes| bytes.checked_add(digest.size))\n            .ok_or_else(|| eyre!(\"remote cache blob pack is too large\"))?;\n        payload_bytes = payload_bytes\n            .checked_add(digest.size)\n            .ok_or_else(|| eyre!(\"remote cache blob pack payload is too large\"))?;\n\n        let path = directory.path().join(blobs.len().to_string());\n        let mut output = tokio::fs::File::create(&path).await?;\n        let mut remaining = digest.size;\n        let mut buffer = [0_u8; 64 * 1024];\n        while remaining > 0 {\n            let limit = usize::try_from(remaining.min(buffer.len() as u64)).unwrap();","sourceCodeStart":805,"sourceCodeEnd":841,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/crates/mise-cache-core/src/lib.rs#L805-L841","documentation":"While decoding a blob pack, each entry's reconstructed CacheDigest must be one of the digests the client actually requested. If the server returns an entry for an unrequested digest, the client bails — the pack stream does not match the request and cannot be trusted. A subsequent check similarly rejects duplicate entries for the same digest.","triggerScenarios":"get_blob_pack with a digest list where the decoded pack contains an entry whose algorithm/hash/size is not in the requested set — e.g. a buggy server echoing extra blobs, or a client bug sending a subset different from what it decodes against.","commonSituations":"Server-side pack assembly bugs including extra objects; protocol skew where the server interprets the digest list differently; intermediaries returning a cached pack for a different request (cache-key collision on the pack endpoint).","solutions":["Verify the request body (DigestList JSON) and response entries match; capture both with a proxy or curl","Fix/upgrade the server so packs contain exactly the requested digests","Check whether a shared cache/proxy is serving a pack generated for a different digest list — disable caching on the blobs:pack route","Retry; if persistent, avoid blob packs (single-blob endpoint is unaffected)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-validate what you request so any extra server entries are detectable:\nlet requested: BTreeSet<CacheDigest> = digests.iter().cloned().collect();\n// after decoding: every entry must be in `requested` and unique","typeGuard":"fn all_requested(entries: &[CacheDigest], requested: &BTreeSet<CacheDigest>) -> bool {\n    entries.iter().all(|d| requested.contains(d))\n}","tryCatchPattern":"match client.get_blob_pack(&digests, staging).await {\n    Err(e) if e.to_string().contains(\"unrequested digest\") => {\n        // server bug or proxy cache-key collision; fall back to single-blob fetches\n    }\n    other => other?,\n}","preventionTips":["Exclude the blobs:pack route from shared caches that might key packs loosely","Deduplicate the digest list before requesting (the library dedupes internally)","Report persistent unrequested-digest responses as a server pack-assembly bug"],"tags":["remote-cache","blob-pack","integrity"],"backgroundTag":"unexpected-response-shape","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"}