{"record":{"id":"acd1c4a51cc6b8a5","repo":"BigPizzaV3/CodexPlusPlus","slug":"error-acd1c4","errorCode":null,"errorMessage":"下载内容超过 {} 字节限制","messagePattern":"下载内容超过 (.+?) 字节限制","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/dream_skin_market.rs","lineNumber":267,"sourceCode":"}\n\nasync fn download_limited(\n    client: &reqwest::Client,\n    url: &str,\n    limit: usize,\n) -> anyhow::Result<Vec<u8>> {\n    let response = client\n        .get(url)\n        .send()\n        .await\n        .with_context(|| format!(\"请求失败：{url}\"))?\n        .error_for_status()\n        .with_context(|| format!(\"服务器返回错误状态：{url}\"))?;\n    if response\n        .content_length()\n        .is_some_and(|size| size > limit as u64)\n    {\n        bail!(\"下载内容超过 {} 字节限制\", limit);\n    }\n    let mut stream = response.bytes_stream();\n    let mut bytes = Vec::new();\n    while let Some(chunk) = stream.next().await {\n        let chunk = chunk.context(\"读取下载内容失败\")?;\n        if bytes.len().saturating_add(chunk.len()) > limit {\n            bail!(\"下载内容超过 {} 字节限制\", limit);\n        }\n        bytes.extend_from_slice(&chunk);\n    }\n    if bytes.is_empty() {\n        bail!(\"下载内容为空\");\n    }\n    Ok(bytes)\n}\n\nfn cache_manifest(state_dir: &Path, manifest: &DreamSkinMarketManifest) -> anyhow::Result<()> {\n    let bytes = serde_json::to_vec_pretty(manifest)?;","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/dream_skin_market.rs#L249-L285","documentation":"`download_limited` performs a size-capped HTTP download. Before streaming, it checks the `Content-Length` response header; if the server declares a body larger than the configured `limit`, the download is aborted immediately. This protects the app from unbounded memory use when a market manifest or theme asset is unexpectedly huge.","triggerScenarios":"Calling `fetch_market_manifest` or `install_market_theme_from_base` (which route through `download_limited`) against a URL whose response declares `Content-Length` greater than the limit (manifest limit or asset limit). Requires the server to send a Content-Length header (chunked responses skip this check and hit error 162 instead).","commonSituations":"A misconfigured or malicious market server pointing the manifest at a multi-gigabyte file; a theme asset URL that actually hosts an archive far larger than the allowed theme/image size; a redirect landing on the wrong resource.","solutions":["Check the URL being fetched: if it is wrong (e.g. pointing at a full archive instead of a small index), correct the market base URL or asset path in the manifest.","If the resource is legitimately large, increase the configured size limit passed to `download_limited` (e.g. the `MARKET_INDEX_LIMIT`-style constant for manifests) in the caller.","Verify with `curl -I <url>` what the server reports as Content-Length and fix the server-side file if it was replaced by a larger one.","For chunked/unknown-length oversized responses, the equivalent stream-phase check (error at line 274) will fire; the fix is the same."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// pre-flight with reqwest::Client::new()\nlet len = client.head(url).send().await?.content_length();\nif let Some(n) = len {\n    anyhow::ensure!(n <= limit, \"resource too large: {n} > {limit}\");\n}","typeGuard":null,"tryCatchPattern":"match download_limited(&client, &url, LIMIT).await {\n    Err(e) if e.to_string().contains(\"字节限制\") => {\n        // skip this asset / surface size error to user\n    }\n    other => other?,\n}","preventionTips":["Keep market index and asset files well under the configured size limits","Use HEAD requests to check Content-Length before large downloads","Monitor market server files so a replaced asset cannot silently grow past the cap","Prefer static file hosts that report accurate Content-Length"],"tags":["network","http","download","size-limit"],"backgroundTag":"payload-too-large","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}