File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed
crates/uv/src/commands/project Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -1754,12 +1754,34 @@ fn copy_entrypoint(
1754
1754
previous_executable : & Path ,
1755
1755
python_executable : & Path ,
1756
1756
) -> Result < ( ) , CopyEntrypointError > {
1757
- use std:: io:: Write ;
1757
+ use std:: io:: { Seek , Write } ;
1758
1758
use std:: os:: unix:: fs:: PermissionsExt ;
1759
1759
1760
1760
use fs_err:: os:: unix:: fs:: OpenOptionsExt ;
1761
1761
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) ?;
1763
1785
1764
1786
let Some ( contents) = contents
1765
1787
// Check for a relative path or relocatable shebang
You can’t perform that action at this time.
0 commit comments