BigPizzaV3/CodexPlusPlus · error
theme.css 规则数量超过限制
Error message
theme.css 规则数量超过限制
What it means
parse_safe_css enforces a hard cap of 128 CSS rules when parsing a Dream Skin theme package's theme.css. After each rule is pushed, if the count exceeds 128 the parser bails with this message. This limits resource usage and attack surface of third-party skin CSS.
Solutions
- Reduce the number of rules in theme.css to 128 or fewer by merging selectors that share declarations.
- Split the theme into multiple skin packages or drop non-essential parts.
- Generate a rule-count report before packaging and trim the largest rule groups.
Example fix
/* before: 130 rules like */
.ds-part["header"] { color: #111; }
.ds-part["footer"] { color: #111; }
/* ... x130 */
/* after: merge selectors sharing declarations */
.ds-part["header"], .ds-part["footer"] { color: #111; } Defensive patterns
Strategy: validation
Validate before calling
fn rule_count_ok(css: &str) -> bool {
css.match_indices('}').count() <= 128
}
if !rule_count_ok(&theme_css) { /* trim rules before validating */ } Try / catch
match validate_safe_css(&css) {
Ok(rules) => apply(rules),
Err(e) if e.to_string().contains("规则数量超过限制") => eprintln!("trim theme.css to <= 128 rules"),
Err(e) => return Err(e),
} Prevention
- Count selectors/rules at build time before packaging.
- Merge selectors sharing identical declarations.
- Keep themes modular and small.
When it happens
Trigger: Calling validate_safe_css or compile_safe_css (directly or via validate_and_read_package) with a theme.css containing more than 128 rules (i.e. the 129th closing brace is parsed and parsed.len() becomes 129 > 128).
Common situations: Authors exporting a full site theme or a large design-system stylesheet into a skin package; hand-editing theme.css by adding many selectors; automated CSS dump from a build tool pasted into theme.css.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- theme.css 必须至少包含一条规则
- theme.css 每条规则必须至少包含一个声明
- theme.css CSS 属性无效或重复:
- 主题包必须是 32 MiB 以内的普通 ZIP 文件
- 请填写 API 的模型名称
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/4bee7e8e3d3fa683.
Report an issue: GitHub.
Appendix: source
Thrown at crates/codex-plus-core/src/dream_skin_package.rs:382
{
bail!("theme.css 属性值不受 Safe CSS 支持:{property}");
}
declarations += 1;
if declarations > 512 {
bail!("theme.css 声明数量超过限制");
}
rule_declarations.push((property, value));
}
if rule_declarations.is_empty() {
bail!("theme.css 每条规则必须至少包含一个声明");
}
parsed.push(SafeCssRule {
selector,
part,
declarations: rule_declarations,
});
if parsed.len() > 128 {
bail!("theme.css 规则数量超过限制");
}
rest = &rest[close + 1..];
}
if parsed.is_empty() {
bail!("theme.css 必须至少包含一条规则");
}
Ok(parsed)
}
fn forbidden_css_character(character: char) -> bool {
matches!(
character as u32,
0x0000..=0x0008 | 0x000b | 0x000e..=0x001f | 0x007f..=0x009f
| 0x2028 | 0x2029 | 0x200e | 0x200f | 0x202a..=0x202e | 0x2066..=0x2069 | 0xfeff
)
}
fn validate_property_value(property: &str, value: &str) -> bool {View on GitHub (pinned to b1ed92e5e4)