BigPizzaV3/CodexPlusPlus · error

主题包路径不安全:

Error message

主题包路径不安全:{name}

What it means

validate_archive_entry_name rejects unsafe entry names inside a Dream Skin .dskin zip archive before contents are read. A name that is empty, starts with '/', or contains a backslash is rejected with this message to prevent path traversal and Windows absolute/escape paths.

Solutions

  1. Rebuild the package so entry names are relative, use '/' separators, and start without a slash.
  2. Repack with a standard tool (zip/7z) rather than custom archive writers.
  3. If you are the packager, normalize names before writing entries (strip leading '/', replace '\\' with '/').

Example fix

// before (custom writer)
let entry = add_entry("/theme/theme.css", data);
// after
let entry = add_entry("theme/theme.css", data);
Defensive patterns

Strategy: validation

Validate before calling

fn entry_name_safe(name: &str) -> bool {
    !name.is_empty() && !name.starts_with('/') && !name.contains('\\')
}
// call for every zip entry before writing

Try / catch

match validate_and_read_package(path, platform) {
    Ok(pkg) => install(pkg),
    Err(e) if e.to_string().contains("路径不安全") => eprintln!("repack archive with relative '/'-separated names"),
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: validate_and_read_package encounters an archive entry whose name is "", "/etc/passwd", "foo\\bar.css", or otherwise begins with a slash or contains a backslash.

Common situations: Hand-crafted or tool-modified zip files with absolute paths; archives built on Windows with backslash separators; tampered packages distributed online.

Understand the failure class

Background: Path traversal blocked: "path escapes the workspace" and "outside site root" errors when a path will not stay inside its allowed directory — this error's family across 26 libraries.

Related errors


AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19). Data as JSON: /api/errors/7b2c5d5c225ec0bb. Report an issue: GitHub.

Appendix: source

Thrown at crates/codex-plus-core/src/dream_skin_package.rs:819

            }
            "saturate" => numeric(argument, "", 0.5, 2.0),
            "brightness" | "contrast" => numeric(argument, "", 0.8, 1.5),
            _ => false,
        };
        if !valid {
            return false;
        }
    }
    seen.contains("blur")
}

fn parse_json<T: serde::de::DeserializeOwned>(bytes: &[u8], label: &str) -> anyhow::Result<T> {
    serde_json::from_slice(bytes).with_context(|| format!("{label} 不是有效 JSON"))
}

fn validate_archive_entry_name(name: &str) -> anyhow::Result<()> {
    if name.is_empty() || name.starts_with('/') || name.contains('\\') {
        bail!("主题包路径不安全:{name}");
    }
    if name != name.trim()
        || name.contains(['\0', ':'])
        || name.split('/').any(|part| part == "." || part == "..")
        || (!name.starts_with("__MACOSX/")
            && name.split('/').filter(|part| !part.is_empty()).count() > 2)
    {
        bail!("主题包文件名不安全:{name}");
    }
    Ok(())
}

fn normalize_package_entries(
    entries: Vec<(String, Option<Vec<u8>>)>,
) -> anyhow::Result<std::collections::BTreeMap<String, Vec<u8>>> {
    let content_entries = entries
        .into_iter()
        .filter_map(|(name, content)| content.map(|content| (name, content)))

View on GitHub (pinned to b1ed92e5e4)