diff options
| author | 2021-04-06 16:07:48 -0700 | |
|---|---|---|
| committer | 2021-04-06 16:16:47 -0700 | |
| commit | 3072fffec237b05bba469c346918e1dcd83e8521 (patch) | |
| tree | be101bdb6dd1f227940e71dc68879f979bc18506 /config | |
| parent | Bump urllib3 from 1.26.3 to 1.26.4 (diff) | |
Use PYTHONIOENCODING to enable utf-8 stdout for the nsjail pipe, and handle the potential case where this is bypassable
Since snekbox does not run with a tty, stdout is technically raw bytes, and thus incomplete surrogate pairs can be printed without the client application erroring, and instead fail within _consume_stdout when we attempt to decode it to a str.
This commit sets the PYTHONIOENCODING environment variable to inform python to open the pipe in utf-8 mode.
However, clever use of execl and os.unsetenv() can unset this environment variable, so we add a safety check to _consume_stdout to fail out of parsing output if it contains invalid unicode. This should only happen in deliberate cases, or significant bugs in python or a c library where output is printed to stdout ignoring the python stdout encoding.
Diffstat (limited to 'config')
| -rw-r--r-- | config/snekbox.cfg | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/config/snekbox.cfg b/config/snekbox.cfg index 257b5ca..73e36e1 100644 --- a/config/snekbox.cfg +++ b/config/snekbox.cfg @@ -15,6 +15,7 @@ envar: "MKL_NUM_THREADS=1" envar: "VECLIB_MAXIMUM_THREADS=1" envar: "NUMEXPR_NUM_THREADS=1" envar: "PYTHONPATH=/snekbox/user_base/lib/python3.9/site-packages" +envar: "PYTHONIOENCODING=utf-8:strict" keep_caps: false |