{"record":{"id":"825ce067f8385d41","repo":"jdx/mise","slug":"remote-cache-blob-pack-has-invalid-magic","errorCode":null,"errorMessage":"remote cache blob pack has invalid magic","messagePattern":"remote cache blob pack has invalid magic","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/mise-cache-core/src/lib.rs","lineNumber":792,"sourceCode":"    let item_units = digests.len().div_ceil(BLOB_PACK_TIMEOUT_ITEMS_PER_UNIT);\n    let item_units = u64::try_from(item_units).unwrap_or(u64::MAX);\n    let multiplier = byte_units.max(item_units).max(1);\n    base.saturating_mul(u32::try_from(multiplier).unwrap_or(u32::MAX))\n}\n\nasync fn decode_blob_pack(\n    response: reqwest::Response,\n    requested: &[CacheDigest],\n    staging_dir: &Path,\n) -> Result<DownloadedBlobPack> {\n    let metadata = BlobPackResponseMetadata::from_headers(response.headers())?;\n    let requested = requested.iter().cloned().collect::<BTreeSet<_>>();\n    let stream = response.bytes_stream().map_err(std::io::Error::other);\n    let mut reader = tokio_util::io::StreamReader::new(stream);\n    let mut magic = [0_u8; BLOB_PACK_MAGIC.len()];\n    reader.read_exact(&mut magic).await?;\n    if &magic != BLOB_PACK_MAGIC {\n        bail!(\"remote cache blob pack has invalid magic\");\n    }\n\n    let directory = tempfile::tempdir_in(staging_dir)?;\n    let mut seen = BTreeSet::new();\n    let mut blobs = Vec::new();\n    let mut payload_bytes = 0_u64;\n    let mut framed_bytes = BLOB_PACK_MAGIC.len() as u64;\n    loop {\n        let mut algorithm = [0_u8; 1];\n        if reader.read(&mut algorithm).await? == 0 {\n            break;\n        }\n        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())),","sourceCodeStart":774,"sourceCodeEnd":810,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/crates/mise-cache-core/src/lib.rs#L774-L810","documentation":"decode_blob_pack reads the blob-pack stream and expects it to begin with the fixed BLOB_PACK_MAGIC bytes. If the leading bytes don't match, the payload is not a valid blob pack and the client bails. This detects proxies/HTML error pages, wrong endpoints, or format-version mismatches masquerading as a 200 pack response.","triggerScenarios":"POSTing to blobs:pack and receiving a 200 response with correct Content-Type but a body that does not start with the pack magic — e.g. an intercepted response, a server-side format change, or a completely different binary format.","commonSituations":"Transparent proxies rewriting bodies; server upgraded to an incompatible pack format; a server bug writing the wrong framing header; response body corruption.","solutions":["Capture the response body (curl --raw) and inspect the leading bytes","Confirm the server's pack format version matches the client's expected magic; upgrade whichever side lags","Bypass intermediaries to rule out body rewriting","As a workaround, let blob packs fail once — get_blob_pack disables packs after a hard error path and callers fall back to single-blob downloads"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Peek the first bytes of a pack response yourself before decoding:\nlet mut magic = [0u8; MAGIC.len()];\nreader.read_exact(&mut magic).await?;\nif &magic != BLOB_PACK_MAGIC { bail!(\"not a blob pack\"); }","typeGuard":null,"tryCatchPattern":"match client.get_blob_pack(&digests, staging).await? {\n    Some(pack) => use_pack(pack),\n    None => {\n        // packs unavailable/failed handshake — fetch each digest via get_blob/get_blob_file\n    }\n}","preventionTips":["Keep client and server pack-format versions in sync","Bypass proxies that may rewrite binary bodies","After a pack decode failure, rely on the library disabling packs and the single-blob fallback path"],"tags":["remote-cache","blob-pack","format"],"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"}