{"record":{"id":"5664746214e3ae55","repo":"BigPizzaV3/CodexPlusPlus","slug":"sha-256","errorCode":null,"errorMessage":"主题市场包含无效 SHA-256","messagePattern":"主题市场包含无效 SHA-256","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/dream_skin_market.rs","lineNumber":380,"sourceCode":"    Ok(())\n}\n\nfn valid_theme_id(value: &str) -> bool {\n    let bytes = value.as_bytes();\n    (1..=64).contains(&bytes.len())\n        && bytes[0].is_ascii_alphanumeric()\n        && bytes.iter().all(|byte| {\n            byte.is_ascii_lowercase() || byte.is_ascii_digit() || matches!(byte, b'-' | b'_')\n        })\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\")","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/dream_skin_market.rs#L362-L398","documentation":"validate_sha256 checks that a theme-market hash string is exactly 64 lowercase hex characters (0-9, a-f). The library throws this when any SHA-256 value entering the theme market validation path (validate_market_theme or verify_sha256) is malformed. It is a pre-check before any hashing comparison, ensuring hashes are canonical.","triggerScenarios":"Calling validate_market_theme with a theme whose sha256 field is empty, not 64 chars, contains uppercase hex (A-F), whitespace, '0x' prefix, or any non-lowercase-hex byte; verify_sha256 also calls it first on the expected value, so an invalid manifest hash triggers this instead of a checksum mismatch.","commonSituations":"Marketplace manifest generated by a tool emitting uppercase hex digests, hand-edited manifest with truncated hash, copy-paste introducing spaces/quotes, non-hash placeholder values in theme metadata.","solutions":["Recompute the hash with lowercase hex output: `sha256sum file | awk '{print $1}'` and put that 64-char value in the manifest","Check for and remove uppercase letters — convert with `tr 'A-F' 'a-f'`","Verify the field is not empty or truncated (exactly 64 characters)","Strip whitespace/quotes around the value in the manifest JSON"],"exampleFix":"// before\n\"sha256\": \"A3F1...\"\n// after\n\"sha256\": \"a3f1...\"","handlingStrategy":"validation","validationCode":"fn is_valid_sha256(s: &str) -> bool {\n    s.len() == 64 && s.bytes().all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b))\n}\nif !is_valid_sha256(&theme.sha256) { return Err(InvalidThemeHash); }","typeGuard":"fn as_sha256(s: &str) -> Option<&str> {\n    (s.len() == 64 && s.bytes().all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b))).then_some(s)\n}","tryCatchPattern":"match validate_market_theme(&theme) {\n    Err(e) if e.to_string().contains(\"无效 SHA-256\") => regenerate_hash_and_retry(),\n    Err(e) => return Err(e),\n    Ok(v) => v,\n}","preventionTips":["Always generate hashes with lowercase hex output (sha256sum, hex::encode)","Validate the hash field at manifest-creation time, before publishing","Never hand-edit hash strings; copy them directly from tool output"],"tags":["validation","hash","rust"],"backgroundTag":"invalid-argument-format","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"}