{"record":{"id":"425b304cd7dfb7cc","repo":"BigPizzaV3/CodexPlusPlus","slug":"theme-css-256-kib","errorCode":null,"errorMessage":"theme.css 为空或超过 256 KiB 限制","messagePattern":"theme\\.css 为空或超过 256 KiB 限制","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/dream_skin_package.rs","lineNumber":278,"sourceCode":"            compiled.push_str(rule.selector);\n            compiled.push_str(\" :where(button:not([class~=\\\"bg-token-foreground\\\"]), button:not([class~=\\\"bg-token-foreground\\\"]) *) {\\n\");\n            compiled.push_str(&format!(\"    color: {value} !important;\\n  }}\\n\"));\n        }\n    }\n    compiled.push_str(\"}\\n\");\n    Ok(compiled)\n}\n\n#[derive(Debug)]\nstruct SafeCssRule<'a> {\n    selector: &'a str,\n    part: &'a str,\n    declarations: Vec<(&'a str, &'a str)>,\n}\n\nfn parse_safe_css(css: &str) -> anyhow::Result<Vec<SafeCssRule<'_>>> {\n    if css.is_empty() || css.len() > CSS_LIMIT {\n        bail!(\"theme.css 为空或超过 256 KiB 限制\");\n    }\n    if css.chars().any(forbidden_css_character)\n        || css.contains(\"/*\")\n        || css.contains(\"*/\")\n        || css.contains('\\\\')\n    {\n        bail!(\"theme.css 包含不允许的控制字符、注释或转义\");\n    }\n    let allowed_parts = [\n        \"root\",\n        \"sidebar\",\n        \"main\",\n        \"header\",\n        \"home\",\n        \"home-hero\",\n        \"project-list\",\n        \"thread\",\n        \"message\",","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/dream_skin_package.rs#L260-L296","documentation":"parse_safe_css (used by validate_safe_css and compile_safe_css) first requires theme.css to be non-empty and at most CSS_LIMIT = 262144 bytes (256 KiB, measured with str::len, i.e. UTF-8 bytes). An empty stylesheet carries no rules and an oversized one would let a package push huge payloads into the renderer, so both are rejected outright with 'theme.css 为空或超过 256 KiB 限制'.","triggerScenarios":"validate_safe_css(\"\") or compile_safe_css with an empty string; any theme.css whose byte length exceeds 262144, even if the extra bytes are whitespace or comments; a zip entry read produced empty css_bytes in validate_and_read_package (though that usually fails earlier with '超过大小限制').","commonSituations":"Theme authors accidentally shipping a zero-byte theme.css after an editor mishap; hand-written CSS that grew past 256 KiB with copied-in reset sheets or huge font stacks; build tooling emitting an empty file when a template fails to render.","solutions":["Check the file: `wc -c theme.css` — if 0, write real rules; if > 262144, trim it","Split or minify the CSS: remove redundant rules, merge selectors for the same [data-ds-part], drop unused declarations","Keep only the whitelisted properties (colors, borders, box-shadow, fonts, transitions, backdrop-filter) — arbitrary resets are rejected anyway, so deleting them loses nothing"],"exampleFix":"// before\n$ wc -c theme.css  # 300000\n// after\n# strip rules not targeting [data-ds-part=...] and re-check\n$ wc -c theme.css  # 24000","handlingStrategy":"validation","validationCode":"fn css_size_ok(css: &str) -> bool {\n    !css.is_empty() && css.len() <= 256 * 1024\n}","typeGuard":"fn is_non_empty_css(input: Option<&str>) -> bool {\n    input.map_or(false, |css| !css.trim().is_empty() && css.len() <= 262_144)\n}","tryCatchPattern":"match validate_safe_css(&css) {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"256 KiB\") => return Err(\"theme.css is empty or exceeds 256 KiB\".into()),\n    Err(e) => return Err(e),\n}","preventionTips":["Check file size (must be 1-262144 bytes) before packaging","Minify and strip dead rules to stay well under 256 KiB","Never ship an empty placeholder theme.css; every rule must also have declarations"],"tags":["css","size-limit","dream-skin"],"backgroundTag":"file-size-limit-exceeded","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"}