Skip to content

Commit a931647

Browse files
committed
Avoid reading files in the environment bin that are not entrypointse
1 parent f0151f3 commit a931647

File tree

1 file changed

+24
-2
lines changed
  • crates/uv/src/commands/project

1 file changed

+24
-2
lines changed

crates/uv/src/commands/project/run.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,12 +1754,34 @@ fn copy_entrypoint(
17541754
previous_executable: &Path,
17551755
python_executable: &Path,
17561756
) -> Result<(), CopyEntrypointError> {
1757-
use std::io::Write;
1757+
use std::io::{Seek, Write};
17581758
use std::os::unix::fs::PermissionsExt;
17591759

17601760
use fs_err::os::unix::fs::OpenOptionsExt;
17611761

1762-
let contents = fs_err::read_to_string(source)?;
1762+
let mut file = fs_err::File::open(source)?;
1763+
let mut buffer = [0u8; 2];
1764+
if file.read_exact(&mut buffer).is_err() {
1765+
// File is too small to have a shebang
1766+
trace!(
1767+
"Skipping copy of entrypoint `{}`: file is too small to contain a shebang",
1768+
source.user_display()
1769+
);
1770+
return Ok(());
1771+
}
1772+
1773+
// Check if it starts with `#!` to avoid reading binary files and such into memory
1774+
if &buffer != b"#!" {
1775+
trace!(
1776+
"Skipping copy of entrypoint `{}`: does not start with #!",
1777+
source.user_display()
1778+
);
1779+
return Ok(());
1780+
}
1781+
1782+
let mut contents = String::new();
1783+
file.seek(std::io::SeekFrom::Start(0))?;
1784+
file.read_to_string(&mut contents)?;
17631785

17641786
let Some(contents) = contents
17651787
// Check for a relative path or relocatable shebang

0 commit comments

Comments
 (0)