Skip to content

Commit 03593b1

Browse files
committed
Fix security issue in sio.executors.encdec_common
1 parent 4fddf4b commit 03593b1

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

sio/executors/encdec_common.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
from __future__ import absolute_import
22
import os
33
import logging
4-
from shutil import rmtree
4+
from shutil import copy2, rmtree
55
import tempfile
66
from zipfile import ZipFile, is_zipfile
77
from sio.executors.checker import _limit_length
88
from sio.executors.common import _run_core
99
from sio.workers import ft
1010
from sio.workers.executors import ExecError, PRootExecutor, UnprotectedExecutor
11-
from sio.workers.util import decode_fields, replace_invalid_UTF, tempcwd
11+
from sio.workers.util import decode_fields, replace_invalid_UTF, tempcwd, TemporaryCwd
1212
from sio.workers.file_runners import get_file_runner
1313

14-
# TODO XXX FIXME
15-
# Hide the files like enc_in or hint from the contestants
16-
# Would not be nice if someone just sideloaded enc_in in decoder
17-
1814
import six
1915

2016
logger = logging.getLogger(__name__)
@@ -214,6 +210,23 @@ def _run_checker(environ, use_sandboxes=False):
214210
return False
215211

216212

213+
def _run_decoder_hide_files(environ, file_executor, exe_filename, use_sandboxes, orig_dir):
214+
# We now have quite a lot of interes
215+
# be nice if some decoder read them.
216+
with TemporaryCwd() as new_dir:
217+
# Copy the executable and input
218+
for f in 'dec_in', exe_filename:
219+
copy2(os.path.join(orig_dir, f), tempcwd(f))
220+
221+
renv = _run_decoder(environ, file_executor, exe_filename, use_sandboxes)
222+
223+
# Copy the output
224+
for f in 'dec_out',:
225+
copy2(tempcwd(f), os.path.join(orig_dir, f))
226+
227+
return renv
228+
229+
217230
def run(environ, executor, use_sandboxes=True):
218231
"""
219232
Common code for executors.
@@ -244,7 +257,7 @@ def run(environ, executor, use_sandboxes=True):
244257
if not _run_channel(environ, use_sandboxes):
245258
return environ
246259

247-
renv = _run_decoder(environ, file_executor, exe_filename, use_sandboxes)
260+
renv = _run_decoder_hide_files(environ, file_executor, exe_filename, use_sandboxes, tempcwd())
248261
_populate_environ(renv, environ, "decoder_")
249262

250263
if renv["result_code"] != "OK":

0 commit comments

Comments
 (0)