{"record":{"id":"441226c02a2983dc","repo":"BigPizzaV3/CodexPlusPlus","slug":"label-sha-256","errorCode":null,"errorMessage":"{label} SHA-256 校验失败","messagePattern":"(.+?) SHA-256 校验失败","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/dream_skin_market.rs","lineNumber":389,"sourceCode":"        })\n}\n\nfn validate_sha256(value: &str) -> anyhow::Result<()> {\n    if value.len() != 64\n        || !value\n            .bytes()\n            .all(|byte| byte.is_ascii_digit() || (b'a'..=b'f').contains(&byte))\n    {\n        bail!(\"主题市场包含无效 SHA-256\");\n    }\n    Ok(())\n}\n\nfn verify_sha256(bytes: &[u8], expected: &str, label: &str) -> anyhow::Result<()> {\n    validate_sha256(expected)?;\n    let actual = format!(\"{:x}\", Sha256::digest(bytes));\n    if actual != expected {\n        bail!(\"{label} SHA-256 校验失败\");\n    }\n    Ok(())\n}\n\nfn detect_image_extension(bytes: &[u8]) -> Option<&'static str> {\n    if bytes.starts_with(b\"\\x89PNG\\r\\n\\x1a\\n\") {\n        Some(\"png\")\n    } else if bytes.starts_with(&[0xff, 0xd8, 0xff]) {\n        Some(\"jpg\")\n    } else if bytes.starts_with(b\"GIF87a\") || bytes.starts_with(b\"GIF89a\") {\n        Some(\"gif\")\n    } else if bytes.starts_with(b\"BM\") {\n        Some(\"bmp\")\n    } else if bytes.len() >= 12 && &bytes[..4] == b\"RIFF\" && &bytes[8..12] == b\"WEBP\" {\n        Some(\"webp\")\n    } else {\n        None\n    }","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/dream_skin_market.rs#L371-L407","documentation":"verify_sha256 first validates the expected hash format via validate_sha256, then hashes the actual bytes with SHA-256 and compares. This error means the downloaded/installed content does not match the declared SHA-256 digest for the given label (e.g. package or image). It guards theme-market installs against corrupted or tampered downloads.","triggerScenarios":"Calling install_market_theme_from_base where the SHA-256 digest of the fetched bytes differs from the `expected` value in the theme manifest — e.g. the base URL served different content, the file was re-uploaded without updating the manifest, or a proxy/CDN modified the payload.","commonSituations":"Theme author updated the asset but not the manifest hash, partial/corrupted download, CDN serving cached old version, MITM or tampering attempt.","solutions":["Re-download the theme asset and retry — the download may have been corrupted","Recompute the correct hash (`sha256sum`) and update the market manifest to match the current asset","Verify the asset URL points at the exact version the manifest describes (pin versions)","If intentional tampering is suspected, reject the theme and obtain it from a trusted source"],"exampleFix":"// before (manifest hash from old asset)\n\"sha256\": \"1111...\"\n// after (hash of current asset)\n\"sha256\": \"<sha256sum current-asset output>\"","handlingStrategy":"retry","validationCode":"let actual = Sha256::digest(&bytes);\nlet expected: [u8; 32] = hex::decode(manifest.sha256).map_err(|_| BadHash)?.try_into()?;\nif actual != expected { return Err(ChecksumMismatch); }","typeGuard":null,"tryCatchPattern":"match install_market_theme_from_base(&url, &manifest).await {\n    Err(e) if e.to_string().ends_with(\"SHA-256 校验失败\") => {\n        warn!(\"checksum mismatch, re-downloading\");\n        retry_download_with_backoff(2)?;\n    }\n    Err(e) => return Err(e),\n    Ok(installed) => installed,\n}","preventionTips":["Pin asset versions so manifest hashes always match served content","Recompute and publish hashes whenever an asset changes","Verify downloads on the server side before publishing the manifest"],"tags":["hash","checksum","integrity","rust"],"backgroundTag":"checksum-mismatch","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"}