BigPizzaV3/CodexPlusPlus · error

invalid Dream Skin destination name

Error message

invalid Dream Skin destination name

What it means

prepare_dream_skin_image_for_directory validates the destination stem before copying a Dream Skin theme image; it must be non-empty and contain only ASCII alphanumerics, '-' or '_'. This prevents unsafe filesystem names and path traversal. import_dream_skin_image is the caller.

Solutions

  1. Sanitize the destination stem before calling: strip the extension and replace disallowed characters with '-' or '_'.
  2. Use ASCII slugs for theme names; if the user name is non-ASCII, transliterate or hash it into [A-Za-z0-9_-].
  3. Ensure the stem is non-empty after sanitization (fallback to a generated name like 'theme-<timestamp>').

Example fix

// before
import_dream_skin_image(source, dir, "我的 主题.png")?;
// after
let stem: String = "我的 主题.png"
    .chars()
    .map(|c| if c.is_ascii_alphanumeric() || c == '-' || c == '_' { c } else { '-' })
    .collect();
import_dream_skin_image(source, dir, stem.trim_matches('-'))?;
Defensive patterns

Strategy: validation

Validate before calling

// TypeScript-side (Tauri frontend) pre-check before invoking import
function isValidDreamSkinStem(stem: string): boolean {
  return /^[A-Za-z0-9_-]+$/.test(stem);
}
if (!isValidDreamSkinStem(userProvidedStem)) throw new Error("theme name must be [A-Za-z0-9_-]");

Type guard

fn is_safe_stem(stem: &str) -> bool {
    !stem.is_empty()
        && stem.bytes().all(|b| b.is_ascii_alphanumeric() || matches!(b, b'-' | b'_'))
}

Prevention

When it happens

Trigger: import_dream_skin_image is called with a destination_stem that is empty or contains characters outside [A-Za-z0-9_-] (e.g. spaces, CJK characters, dots, slashes, '../').

Common situations: User names an imported theme after the original image filename containing spaces or Chinese characters; UI passes the raw filename instead of a sanitized stem; an attempted path traversal ('../evil') is blocked.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


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

Appendix: source

Thrown at crates/codex-plus-core/src/dream_skin.rs:49

pub fn import_dream_skin_image(source: &Path, state_dir: &Path) -> anyhow::Result<PathBuf> {
    let managed_dir = state_dir.join(MANAGED_THEME_DIR);
    let destination = prepare_dream_skin_image_for_directory(source, &managed_dir, "current")?;
    remove_other_managed_images(&managed_dir, &destination)?;
    Ok(destination)
}

pub(crate) fn prepare_dream_skin_image_for_directory(
    source: &Path,
    destination_dir: &Path,
    destination_stem: &str,
) -> anyhow::Result<PathBuf> {
    if destination_stem.is_empty()
        || !destination_stem
            .bytes()
            .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_'))
    {
        bail!("invalid Dream Skin destination name");
    }
    let metadata = std::fs::symlink_metadata(source)
        .with_context(|| format!("failed to read image metadata {}", source.display()))?;
    if !metadata.file_type().is_file() || metadata.file_type().is_symlink() {
        bail!("Dream Skin image is not a file");
    }
    if metadata.len() == 0 {
        bail!("Dream Skin image is empty");
    }
    if metadata.len() > DREAM_SKIN_SOURCE_LIMIT {
        bail!("Dream Skin source image exceeds 50 MiB");
    }

    let extension = supported_image_extension(source)?;
    std::fs::create_dir_all(destination_dir).with_context(|| {
        format!(
            "failed to create Dream Skin theme directory {}",
            destination_dir.display()

View on GitHub (pinned to b1ed92e5e4)