{"record":{"id":"134918db17f19e17","repo":"BigPizzaV3/CodexPlusPlus","slug":"manifest-files-sha-256","errorCode":null,"errorMessage":"manifest.files 的 SHA-256 或大小不匹配：{}","messagePattern":"manifest\\.files 的 SHA-256 或大小不匹配：(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/dream_skin_package.rs","lineNumber":1133,"sourceCode":"            \"LICENSE.txt\" => license_bytes.context(\"manifest 声明了 LICENSE.txt 但包内缺失\")?,\n            \"manifest.sig\" => continue,\n            _ => continue,\n        };\n        let expected_media_type = match file.path.as_str() {\n            \"theme.json\" => \"application/json\",\n            \"theme.css\" => \"text/css\",\n            \"background.webp\" => \"image/webp\",\n            \"background.jpg\" => \"image/jpeg\",\n            \"background.png\" => \"image/png\",\n            \"LICENSE.txt\" => \"text/plain\",\n            _ => \"\",\n        };\n        if file.media_type != expected_media_type {\n            bail!(\"manifest.files 的 mediaType 不匹配：{}\", file.path);\n        }\n        let actual = format!(\"{:x}\", Sha256::digest(bytes));\n        if file.bytes != bytes.len() || !actual.eq_ignore_ascii_case(&file.sha256) {\n            bail!(\"manifest.files 的 SHA-256 或大小不匹配：{}\", file.path);\n        }\n    }\n    if !seen.contains(\"theme.json\") || !seen.contains(\"theme.css\") || !seen.contains(image_name) {\n        bail!(\"manifest.files 缺少必需文件\");\n    }\n    if seen.contains(\"LICENSE.txt\") != license_bytes.is_some() {\n        bail!(\"manifest.files 的 LICENSE.txt 与包内容不一致\");\n    }\n    Ok(())\n}\n\nfn valid_theme_id(value: &str) -> bool {\n    let mut chars = value.chars();\n    chars.next().is_some_and(|c| c.is_ascii_alphanumeric())\n        && value\n            .chars()\n            .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || matches!(c, '-' | '.'))\n}","sourceCodeStart":1115,"sourceCodeEnd":1151,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/dream_skin_package.rs#L1115-L1151","documentation":"For each manifest.files entry, the library hashes the actual package bytes with SHA-256 and compares both the declared byte size and the digest (case-insensitive) against the manifest. If bytes differs from the real file length, or the sha256 does not match the computed digest, this error names the offending file. This guarantees package contents were not modified or corrupted relative to the signed manifest.","triggerScenarios":"Calling validate_and_read_package where a file listed in manifest.files has different content or size than declared — e.g. the sha256 in the manifest was computed from an older version of theme.css, or the image was re-encoded without regenerating the manifest.","commonSituations":"Editing theme.css or theme.json after generating the manifest; re-compressing the background image; transferring the package over a mode-mangling channel (e.g. text FTP) corrupting bytes; computing the hash over a different file than the one packaged.","solutions":["Recompute sha256 and byte size for every file and regenerate manifest.json after any content change","Repackage the skin with the official packaging tool so hashes/sizes are computed from the final bytes","Verify the package files were not modified or corrupted after signing (compare hashes manually with sha256sum)","Ensure transfer of the package preserves binary content exactly"],"exampleFix":"// regenerate hashes after editing theme.css\n// before (stale manifest)\n{ \"path\": \"theme.css\", \"bytes\": 900, \"sha256\": \"old...\" }\n// after\n$ sha256sum theme.css  # then update manifest\n{ \"path\": \"theme.css\", \"bytes\": 1024, \"sha256\": \"new-64-hex...\" }","handlingStrategy":"validation","validationCode":"import { createHash } from \"node:crypto\";\nimport { readFileSync } from \"node:fs\";\nfor (const f of manifest.files) {\n  const buf = readFileSync(join(pkgDir, f.path));\n  const digest = createHash(\"sha256\").update(buf).digest(\"hex\");\n  if (buf.length !== f.bytes || digest.toLowerCase() !== f.sha256.toLowerCase()) {\n    throw new Error(`${f.path}: recompute sha256/bytes and regenerate manifest.json`);\n  }\n}","typeGuard":"function contentMatches(buf, entry) {\n  const digest = createHash(\"sha256\").update(buf).digest(\"hex\");\n  return buf.length === entry.bytes && digest.toLowerCase() === entry.sha256.toLowerCase();\n}","tryCatchPattern":"try {\n  validateAndReadPackage(pkgPath);\n} catch (e) {\n  if (String(e.message).includes(\"SHA-256\") || String(e.message).includes(\"不匹配\")) {\n    regenerateManifestFrom(pkgPath); // recompute hashes/sizes, re-sign, retry once\n  } else {\n    throw e;\n  }\n}","preventionTips":["Always regenerate manifest.json as the LAST step after any file edit","Run sha256sum on packaged files and diff against the manifest before distribution","Never transfer packages through channels that alter bytes (text-mode transfer, re-encoding)"],"tags":["checksum-mismatch","manifest","integrity","skin-package"],"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"}