fix(model): reject aliased bootstrap destinations
This commit is contained in:
@@ -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::<Result<Vec<_>>>()?;
|
||||
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<PathBuf> {
|
||||
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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user