Skip to content

Commit

Permalink
Do not allow users to submit zip files when we need language detection
Browse files Browse the repository at this point in the history
It is not the use case (it was done mostly for output only), and I
think it's broken now as we look for files called "filename.%l" when
the files in the zip are obviously called something like
"filename.cpp".
  • Loading branch information
stefano-maggiolo committed Dec 7, 2016
1 parent a47ea46 commit 10cb40f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
18 changes: 16 additions & 2 deletions cms/server/contest/handlers/tasksubmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ def post(self, task_name):
self.redirect("/tasks/%s/submissions" % quote(task.name, safe=''))
return

# Required files from the user.
required = set([sfe.filename for sfe in task.submission_format])

# Ensure that the user did not submit multiple files with the
# same name.
if any(len(filename) != 1 for filename in self.request.files.values()):
Expand All @@ -173,9 +176,21 @@ def post(self, task_name):
return

# If the user submitted an archive, extract it and use content
# as request.files.
# as request.files. But only valid for "output only" (i.e.,
# not for submissions requiring a programming language
# identification).
if len(self.request.files) == 1 and \
self.request.files.keys()[0] == "submission":
if any(filename.endswith(".%l") for filename in required):
self.application.service.add_notification(
participation.user.username,
self.timestamp,
self._("Invalid submission format!"),
self._("Please select the correct files."),
NOTIFICATION_ERROR)
self.redirect(
"/tasks/%s/submissions" % quote(task.name, safe=''))
return
archive_data = self.request.files["submission"][0]
del self.request.files["submission"]

Expand Down Expand Up @@ -209,7 +224,6 @@ def post(self, task_name):
# submission format and no more. Less is acceptable if task
# type says so.
task_type = get_task_type(dataset=task.active_dataset)
required = set([sfe.filename for sfe in task.submission_format])
provided = set(self.request.files.keys())
if not (required == provided or (task_type.ALLOW_PARTIAL_SUBMISSION
and required.issuperset(provided))):
Expand Down
23 changes: 18 additions & 5 deletions cms/server/contest/handlers/taskusertest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# Contest Management System - http://cms-dev.github.io/
# Copyright © 2010-2014 Giovanni Mascellani <[email protected]>
# Copyright © 2010-2015 Stefano Maggiolo <[email protected]>
# Copyright © 2010-2016 Stefano Maggiolo <[email protected]>
# Copyright © 2010-2012 Matteo Boscariol <[email protected]>
# Copyright © 2012-2014 Luca Wehrstedt <[email protected]>
# Copyright © 2013 Bernard Blackham <[email protected]>
Expand Down Expand Up @@ -228,6 +228,11 @@ def post(self, task_name):
self.redirect("/testing?%s" % quote(task.name, safe=''))
return

# Required files from the user.
required = set([sfe.filename for sfe in task.submission_format] +
task_type.get_user_managers(task.submission_format) +
["input"])

# Ensure that the user did not submit multiple files with the
# same name.
if any(len(filename) != 1 for filename in self.request.files.values()):
Expand All @@ -241,9 +246,20 @@ def post(self, task_name):
return

# If the user submitted an archive, extract it and use content
# as request.files.
# as request.files. But only valid for "output only" (i.e.,
# not for submissions requiring a programming language
# identification).
if len(self.request.files) == 1 and \
self.request.files.keys()[0] == "submission":
if any(filename.endswith(".%l") for filename in required):
self.application.service.add_notification(
participation.user.username,
self.timestamp,
self._("Invalid test format!"),
self._("Please select the correct files."),
NOTIFICATION_ERROR)
self.redirect("/testing?%s" % quote(task.name, safe=''))
return
archive_data = self.request.files["submission"][0]
del self.request.files["submission"]

Expand Down Expand Up @@ -275,9 +291,6 @@ def post(self, task_name):
# This ensure that the user sent one file for every name in
# submission format and no more. Less is acceptable if task
# type says so.
required = set([sfe.filename for sfe in task.submission_format] +
task_type.get_user_managers(task.submission_format) +
["input"])
provided = set(self.request.files.keys())
if not (required == provided or (task_type.ALLOW_PARTIAL_SUBMISSION
and required.issuperset(provided))):
Expand Down
2 changes: 1 addition & 1 deletion cms/server/contest/templates/task_submissions.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ <h2 style="margin-bottom: 10px">{{ _("Submit a solution") }}</h2>
</fieldset>
</form>
</div>
{% if len(task.submission_format) > 1 %}
{% if len(task.submission_format) > 1 and not any(x.filename.endswith(".%l") for x in task.submission_format) %}
<div class="span4">
<form class="form-horizontal" enctype="multipart/form-data" action="{{ url_root }}/tasks/{{ encode_for_url(task.name) }}/submit" method="POST">
<fieldset>
Expand Down
2 changes: 2 additions & 0 deletions cms/server/contest/templates/test_interface.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ <h2 style="margin-bottom: 10px">{{ _("Submit a test") }}</h2>
</fieldset>
</form>
</div>
{% if not any(x.filename.endswith(".%l") for x in task.submission_format) %}
<div class="span4">
<form class="form-horizontal" enctype="multipart/form-data" action="{{ url_root }}/tasks/{{ encode_for_url(task.name) }}/test" method="POST">
<fieldset>
Expand All @@ -141,6 +142,7 @@ <h2 style="margin-bottom: 10px">{{ _("Submit a test") }}</h2>
</fieldset>
</form>
</div>
{% end %}
</div>


Expand Down

0 comments on commit 10cb40f

Please sign in to comment.