Skip to content

Commit 839cd13

Browse files
committed
fix: validate executable filename before spawning in resolve_environment (Fixes #364)
1 parent b171452 commit 839cd13

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

crates/pet-python-utils/src/executable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub fn find_executables<T: AsRef<Path>>(env_path: T) -> Vec<PathBuf> {
180180
python_executables
181181
}
182182

183-
fn is_python_executable_name(exe: &Path) -> bool {
183+
pub fn is_python_executable_name(exe: &Path) -> bool {
184184
let name = exe
185185
.file_name()
186186
.unwrap_or_default()

crates/pet/src/resolve.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use pet_core::{
1212
Locator,
1313
};
1414
use pet_env_var_path::get_search_paths_from_env_variables;
15-
use pet_python_utils::{env::ResolvedPythonEnv, executable::find_executable};
15+
use pet_python_utils::{
16+
env::ResolvedPythonEnv,
17+
executable::{find_executable, is_python_executable_name},
18+
};
1619

1720
use crate::locators::identify_python_environment_using_locators;
1821

@@ -49,6 +52,16 @@ pub fn resolve_environment(
4952
executable
5053
);
5154
}
55+
// Validate that the executable filename looks like a Python executable
56+
// before proceeding with the locator chain or spawning.
57+
if executable.is_file() && !is_python_executable_name(&executable) {
58+
warn!(
59+
"Path {:?} does not look like a Python executable, skipping resolve",
60+
executable
61+
);
62+
return None;
63+
}
64+
5265
// First check if this is a known environment
5366
let env = PythonEnv::new(executable.to_owned(), None, None);
5467
trace!(

0 commit comments

Comments
 (0)