File tree Expand file tree Collapse file tree 4 files changed +24
-5
lines changed Expand file tree Collapse file tree 4 files changed +24
-5
lines changed Original file line number Diff line number Diff line change
1
+ Prevent tox from using a truncated interpreter when using
2
+ ``TOX_LIMITED_SHEBANG `` -- by :user: `jdknight `.
Original file line number Diff line number Diff line change @@ -1097,9 +1097,9 @@ Handle interpreter directives with long lengths
1097
1097
For systems supporting executable text files (scripts with a shebang), the
1098
1098
system will attempt to parse the interpreter directive to determine the program
1099
1099
to execute on the target text file. When ``tox `` prepares a virtual environment
1100
- in a file container which has a large length (e.x . using Jenkins Pipelines), the
1100
+ in a file container which has a large length (e.g . using Jenkins Pipelines), the
1101
1101
system might not be able to invoke shebang scripts which define interpreters
1102
- beyond system limits (e.x . Linux as a limit of 128; ``BINPRM_BUF_SIZE ``). To
1102
+ beyond system limits (e.g . Linux has a limit of 128; ``BINPRM_BUF_SIZE ``). To
1103
1103
workaround an environment which suffers from an interpreter directive limit, a
1104
1104
user can bypass the system's interpreter parser by defining the
1105
1105
``TOX_LIMITED_SHEBANG `` environment variable before invoking ``tox ``::
Original file line number Diff line number Diff line change 19
19
20
20
from .config import DepConfig
21
21
22
+ #: maximum parsed shebang interpreter length (see: prepend_shebang_interpreter)
23
+ MAXINTERP = 2048
24
+
22
25
23
26
class CreationConfig :
24
27
def __init__ (
@@ -672,7 +675,7 @@ def prepend_shebang_interpreter(args):
672
675
#
673
676
# When preparing virtual environments in a file container which has large
674
677
# length, the system might not be able to invoke shebang scripts which
675
- # define interpreters beyond system limits (e.x . Linux as a limit of 128;
678
+ # define interpreters beyond system limits (e.g . Linux has a limit of 128;
676
679
# BINPRM_BUF_SIZE). This method can be used to check if the executable is
677
680
# a script containing a shebang line. If so, extract the interpreter (and
678
681
# possible optional argument) and prepend the values to the provided
@@ -682,8 +685,9 @@ def prepend_shebang_interpreter(args):
682
685
try :
683
686
with open (args [0 ], "rb" ) as f :
684
687
if f .read (1 ) == b"#" and f .read (1 ) == b"!" :
685
- MAXINTERP = 2048
686
- interp = f .readline (MAXINTERP ).rstrip ().decode ("UTF-8" )
688
+ interp = f .readline (MAXINTERP + 1 ).rstrip ().decode ("UTF-8" )
689
+ if len (interp ) > MAXINTERP : # avoid a truncated interpreter
690
+ return args
687
691
interp_args = interp .split (None , 1 )[:2 ]
688
692
return interp_args + args
689
693
except (UnicodeDecodeError , IOError ):
Original file line number Diff line number Diff line change 9
9
from tox .interpreters import NoInterpreterInfo
10
10
from tox .session .commands .run .sequential import installpkg , runtestenv
11
11
from tox .venv import (
12
+ MAXINTERP ,
12
13
CreationConfig ,
13
14
VirtualEnv ,
14
15
getdigest ,
@@ -1149,6 +1150,18 @@ def test_tox_testenv_interpret_shebang_long_example(tmpdir):
1149
1150
assert args == expected + base_args
1150
1151
1151
1152
1153
+ @pytest .mark .skipif ("sys.platform == 'win32'" , reason = "no shebang on Windows" )
1154
+ def test_tox_testenv_interpret_shebang_skip_truncated (tmpdir ):
1155
+ testfile = tmpdir .join ("check_shebang_truncation.py" )
1156
+ original_args = [str (testfile ), "arg1" , "arg2" , "arg3" ]
1157
+
1158
+ # interpreter (too long example)
1159
+ testfile .write ("#!" + ("x" * (MAXINTERP + 1 )))
1160
+ args = prepend_shebang_interpreter (original_args )
1161
+
1162
+ assert args == original_args
1163
+
1164
+
1152
1165
@pytest .mark .parametrize ("download" , [True , False , None ])
1153
1166
def test_create_download (mocksession , newconfig , download ):
1154
1167
config = newconfig (
You can’t perform that action at this time.
0 commit comments