From ebfa08087fa9112d7fbc4fd65bcaa0162d89ba65 Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Sun, 4 Oct 2026 18:55:15 +0200 Subject: [PATCH] fix(model): reject aliased bootstrap destinations --- control-plane/src/native_model.rs | 38 +++++++++++++++++++++++++++---- scripts/smoke-native-bootstrap.py | 6 +++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/control-plane/src/native_model.rs b/control-plane/src/native_model.rs index a075ff57..ddd36af3 100644 --- a/control-plane/src/native_model.rs +++ b/control-plane/src/native_model.rs @@ -52,12 +52,27 @@ impl NativeModel { directory: a.directory.clone(), })); asset_bundle::validate(&all)?; - // The manifest itself must survive publication and cannot live in a generated tree. - if all + let directories = all .iter() - .any(|a| all.iter().any(|b| a.manifest.starts_with(&b.directory))) - { - return Err("asset manifests must be outside generated directories".into()); + .map(|a| resolved(&a.directory)) + .collect::>>()?; + for (i, directory) in directories.iter().enumerate() { + if directories[..i] + .iter() + .any(|other| directory.starts_with(other) || other.starts_with(directory)) + { + return Err("native model directories overlap through filesystem aliases".into()); + } + } + // The manifest itself must survive publication and cannot live in a generated tree. + for asset in &all { + let manifest = resolved(&asset.manifest)?; + if directories + .iter() + .any(|directory| manifest.starts_with(directory)) + { + return Err("asset manifests must be outside generated directories".into()); + } } Ok(()) } @@ -100,6 +115,19 @@ impl NativeModel { } } +// Resolve existing ancestors too: a new path beneath a symlink can otherwise +// appear lexically disjoint while writing inside another immutable version. +fn resolved(path: &Path) -> Result { + match fs::symlink_metadata(path) { + Ok(_) => Ok(fs::canonicalize(path)?), + Err(e) if e.kind() == std::io::ErrorKind::NotFound => { + let parent = path.parent().ok_or("path has no existing ancestor")?; + Ok(resolved(parent)?.join(path.file_name().ok_or("path component missing")?)) + } + Err(e) => Err(e.into()), + } +} + #[derive(Deserialize, Serialize, PartialEq, Eq)] #[serde(deny_unknown_fields)] struct Entry { diff --git a/scripts/smoke-native-bootstrap.py b/scripts/smoke-native-bootstrap.py index 75d4af4a..e7712559 100644 --- a/scripts/smoke-native-bootstrap.py +++ b/scripts/smoke-native-bootstrap.py @@ -161,6 +161,12 @@ while IFS= read -r line; do case "$line" in QUIT) exit 0 ;; esac; done config = copy.deepcopy(initial) config['native_model']['output'] = str(source / 'inside'); gated_failure() config = copy.deepcopy(initial) + alias = root / 'pack-alias'; alias.symlink_to(output, target_is_directory=True) + config['native_model']['source_dir'] = str(alias / 'new-sources') + gated_failure() + assert not (output / 'new-sources').exists() + alias.unlink() + config = copy.deepcopy(initial) config['engine']['args'].append('--native'); gated_failure() config = copy.deepcopy(initial) config['engine']['tokenizer_dir'] = str(output / 'tokenizer'); gated_failure()