{"record":{"id":"0850ee00ef2b3db1","repo":"spacedriveapp/spacedrive","slug":"downloaded-file-size-mismatch-expected-got","errorCode":null,"errorMessage":"Downloaded file size mismatch: expected {}, got {}","messagePattern":"Downloaded file size mismatch: expected (.+?), got (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"apps/cli/src/domains/update/mod.rs","lineNumber":160,"sourceCode":"\nasync fn download_file(url: &str, expected_size: u64) -> Result<Vec<u8>> {\n\tlet client = reqwest::Client::builder()\n\t\t.user_agent(\"spacedrive-cli\")\n\t\t.build()?;\n\n\tlet response = client.get(url).send().await?;\n\n\tif !response.status().is_success() {\n\t\treturn Err(anyhow::anyhow!(\n\t\t\t\"Failed to download: HTTP {}\",\n\t\t\tresponse.status()\n\t\t));\n\t}\n\n\tlet bytes = response.bytes().await?;\n\n\tif bytes.len() as u64 != expected_size {\n\t\treturn Err(anyhow::anyhow!(\n\t\t\t\"Downloaded file size mismatch: expected {}, got {}\",\n\t\t\texpected_size,\n\t\t\tbytes.len()\n\t\t));\n\t}\n\n\tOk(bytes.to_vec())\n}\n\nfn replace_binary(path: &PathBuf, data: &[u8]) -> Result<()> {\n\tuse std::fs;\n\n\t// Create backup\n\tlet backup_path = path.with_extension(\"bak\");\n\tif path.exists() {\n\t\tfs::copy(path, &backup_path)?;\n\t}\n","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/apps/cli/src/domains/update/mod.rs#L142-L178","documentation":"After downloading, the updater compares bytes.len() against the asset 'size' reported by the GitHub API and rejects mismatches. A difference means the transfer was truncated or re-encoded (transparent gzip by a proxy/CDN), or the asset was replaced after the metadata fetch so the byte count no longer lines up.","triggerScenarios":"Connection dropped mid-body; a proxy re-compressing the binary stream; the release asset re-uploaded between metadata fetch and download.","commonSituations":"Flaky Wi-Fi/VPN links; corporate transparent proxies; mirrors that alter content encoding.","solutions":["Retry 'sd update' on a stable connection","Disable VPN/proxy for the download and retry","Compare the release page's listed asset size with the download; if the release itself is broken, update manually from a previous release"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"#!/usr/bin/env bash\nexpected=$(curl -s https://api.github.com/repos/spacedrive/spacedrive/releases/latest | jq -r '.assets[] | select(.name | contains(\"sd-daemon\")) | .size')\nactual=$(curl -sL <download_url> | wc -c)\n[ \"$actual\" = \"$expected\" ] || { echo \"Size mismatch ($actual != $expected)\"; exit 2; }","typeGuard":null,"tryCatchPattern":"match download_file(&url, expected_size).await {\n    Ok(bytes) => bytes,\n    Err(e) if e.to_string().contains(\"size mismatch\") => {\n        // transient truncation or re-encoding: one full re-download before giving up\n        download_file(&url, expected_size).await?\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Prefer checksums (sha256 in release notes) over byte-length equality; proxies can alter length via content encoding","Disable transparent decompression or compare post-decompress length consistently","Retry once on mismatch before treating the release as broken"],"tags":["network","update","integrity","download"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}