diff --git a/codex-rs/core-plugins/src/plugin_bundle_archive.rs b/codex-rs/core-plugins/src/plugin_bundle_archive.rs index 0063510d7d..2b052a47ab 100644 --- a/codex-rs/core-plugins/src/plugin_bundle_archive.rs +++ b/codex-rs/core-plugins/src/plugin_bundle_archive.rs @@ -213,12 +213,16 @@ fn checked_tar_output_path( let mut has_component = false; for component in entry_name.components() { match component { - std::path::Component::Normal(component) => { + // On Windows, push reparses a nested drive prefix and replaces the destination. + std::path::Component::Normal(component) + if !cfg!(windows) || !component.as_encoded_bytes().contains(&b':') => + { has_component = true; output_path.push(component); } std::path::Component::CurDir => {} - std::path::Component::ParentDir + std::path::Component::Normal(_) + | std::path::Component::ParentDir | std::path::Component::RootDir | std::path::Component::Prefix(_) => { return Err(PluginBundleUnpackError::InvalidBundle(format!( diff --git a/codex-rs/core-plugins/src/plugin_bundle_archive_tests.rs b/codex-rs/core-plugins/src/plugin_bundle_archive_tests.rs index aa77c4661b..6bb8fd4ceb 100644 --- a/codex-rs/core-plugins/src/plugin_bundle_archive_tests.rs +++ b/codex-rs/core-plugins/src/plugin_bundle_archive_tests.rs @@ -1,6 +1,17 @@ use super::*; use tempfile::tempdir; +#[cfg(windows)] +#[test] +fn rejects_nested_drive_prefixes() { + for path in ["package/C:../file", r"package\d:\file"] { + assert!(matches!( + checked_tar_output_path(Path::new(r"C:\staging"), Path::new(path)), + Err(PluginBundleUnpackError::InvalidBundle(_)) + )); + } +} + #[test] fn portable_root_manifest_can_be_packed_and_unpacked() { let source = tempdir().expect("source tempdir");