{"record":{"id":"708617d04297bec5","repo":"BigPizzaV3/CodexPlusPlus","slug":"dream-skin-image-is-empty","errorCode":null,"errorMessage":"Dream Skin image is empty","messagePattern":"Dream Skin image is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codex-plus-core/src/dream_skin.rs","lineNumber":57,"sourceCode":"pub(crate) fn prepare_dream_skin_image_for_directory(\n    source: &Path,\n    destination_dir: &Path,\n    destination_stem: &str,\n) -> anyhow::Result<PathBuf> {\n    if destination_stem.is_empty()\n        || !destination_stem\n            .bytes()\n            .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_'))\n    {\n        bail!(\"invalid Dream Skin destination name\");\n    }\n    let metadata = std::fs::symlink_metadata(source)\n        .with_context(|| format!(\"failed to read image metadata {}\", source.display()))?;\n    if !metadata.file_type().is_file() || metadata.file_type().is_symlink() {\n        bail!(\"Dream Skin image is not a file\");\n    }\n    if metadata.len() == 0 {\n        bail!(\"Dream Skin image is empty\");\n    }\n    if metadata.len() > DREAM_SKIN_SOURCE_LIMIT {\n        bail!(\"Dream Skin source image exceeds 50 MiB\");\n    }\n\n    let extension = supported_image_extension(source)?;\n    std::fs::create_dir_all(destination_dir).with_context(|| {\n        format!(\n            \"failed to create Dream Skin theme directory {}\",\n            destination_dir.display()\n        )\n    })?;\n\n    let (prepared_path, prepared_extension) = prepare_image(source, destination_dir, &extension)?;\n    let prepared_metadata = std::fs::metadata(&prepared_path).with_context(|| {\n        format!(\n            \"failed to read prepared image metadata {}\",\n            prepared_path.display()","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/crates/codex-plus-core/src/dream_skin.rs#L39-L75","documentation":"prepare_dream_skin_image_for_directory rejects the source when symlink_metadata shows it is not a regular file (directory, or a symlink — symlinks are explicitly treated as untrusted). This is a path-traversal/safety guard: Dream Skin imports must be plain image files copied into config directories, never links pointing outside.","triggerScenarios":"import_dream_skin_image is called with a source image whose metadata.len() == 0 (a 0-byte file), detected in prepare_dream_skin_image_for_directory.","commonSituations":"A truncated or failed download that left an empty file; a placeholder file created by a crashed export; a file still being written when import started.","solutions":["Re-export or re-download the image; confirm it opens in an image viewer.","Check the source size before importing (std::fs::metadata(path)?.len() > 0).","If the file is being produced asynchronously, wait for the writer to finish (e.g. rename-into-place pattern) before importing."],"exampleFix":"// before\nimport_dream_skin_image(&maybe_empty, &dir, &stem)?;\n// after\nlet md = std::fs::metadata(&maybe_empty)?;\nanyhow::ensure!(md.len() > 0, \"source image is empty\");\nimport_dream_skin_image(&maybe_empty, &dir, &stem)?;","handlingStrategy":"validation","validationCode":"let md = std::fs::metadata(&source)?;\nif md.len() == 0 { return Err(anyhow!(\"refusing to import empty image\")); }","typeGuard":"fn is_non_empty_file(p: &std::path::Path) -> bool {\n    std::fs::metadata(p).map_or(false, |md| md.len() > 0)\n}","tryCatchPattern":null,"preventionTips":["Verify downloads complete before importing (check size against expected)","Use atomic write-then-rename when producing source images","Sanity-check the image opens in a viewer before automated imports"],"tags":["filesystem","validation","empty-file"],"backgroundTag":"empty-required-field","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"}