Skip to content

Commit

Permalink
Fix viewing testrun results (issue #123) (#124)
Browse files Browse the repository at this point in the history
* Fix for issue #123

Make the testrun controller check whether
the input file is a zip by extension only
and saves that information in the model.

Change a downloaded zipped input file's name,
so it has a .zip extension.

* Revert "Fix for issue #123"

This reverts commit 30f5fa4.

* Fix zipfile handling in testruns (issue #123)

---------

Co-authored-by: pixl.dt <[email protected]>
  • Loading branch information
A-dead-pixel and pixl.dt authored Mar 6, 2023
1 parent b1d88f3 commit 13104de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 7 additions & 4 deletions oioioi/testrun/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,20 @@ def adjust_submission_form(self, request, form, problem_instance):
if form.kind != 'TESTRUN':
return

# We need to check using is_zipfile, as sioworkers do the same.
# Otherwise one could bypass checks and limits for example by
# uploading a zipfile without the '.zip' extension.
def validate_file_size(file):
if (
file.name.upper().endswith(".ZIP")
is_zipfile(file)
and file.size > self.get_testrun_zipped_input_limit()
):
raise ValidationError(_("Zipped input file size limit exceeded."))
elif file.size > self.get_testrun_input_limit():
raise ValidationError(_("Input file size limit exceeded."))

def validate_zip(file):
if file.name.upper().endswith(".ZIP"):
if is_zipfile(file):
archive = Archive(file, '.zip')
if len(archive.filenames()) != 1:
raise ValidationError(_("Archive should have only 1 file inside."))
Expand Down Expand Up @@ -279,7 +282,7 @@ def render_submission(self, request, submission):
context={
'submission': submission_template_context(request, sbm_testrun),
'supported_extra_args': self.get_supported_extra_args(submission),
'input_is_zip': is_zipfile(sbm_testrun.input_file),
'input_is_zip': is_zipfile(sbm_testrun.input_file.read_using_cache()),
},
)

Expand All @@ -295,7 +298,7 @@ def _render_testrun_report(
input_is_zip = False
if testrun_report:
input_is_zip = is_zipfile(
testrun_report.submission_report.submission.programsubmission.testrunprogramsubmission.input_file
testrun_report.submission_report.submission.programsubmission.testrunprogramsubmission.input_file.read_using_cache()
)

return render_to_string(
Expand Down
7 changes: 6 additions & 1 deletion oioioi/testrun/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from zipfile import is_zipfile

from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
from django.urls import reverse
Expand Down Expand Up @@ -127,7 +129,10 @@ def download_input_file_view(request, submission_id):
submission = get_submission_or_error(
request, submission_id, TestRunProgramSubmission
)
return stream_file(submission.input_file, name='input.in')
filename = 'input.in'
if is_zipfile(submission.input_file.read_using_cache()):
filename = 'input.zip'
return stream_file(submission.input_file, name=filename)


@enforce_condition(contest_exists & can_enter_contest)
Expand Down

0 comments on commit 13104de

Please sign in to comment.