Skip to content

Commit

Permalink
Fix JudgeHandler to void leaking submission result via event server (#…
Browse files Browse the repository at this point in the history
…349)

- Remove additional information in broadcasted messages as they are not used
- Do not broadcast `test-case` messages if testcase result visibility is not "Show all testcase result"

The leaked data include number of test cases and time/memory usage.
  • Loading branch information
hieplpvip authored Oct 21, 2023
1 parent 42538ba commit 1ce5bb9
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions judge/bridge/judge_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from judge.caching import finished_submission
from judge.models import Judge, Language, LanguageLimit, Problem, Profile, \
RuntimeVersion, Submission, SubmissionTestCase
from judge.models.problem import ProblemTestcaseResultAccess
from judge.utils.url import get_absolute_submission_file_url

logger = logging.getLogger('judge.bridge')
Expand Down Expand Up @@ -426,14 +427,7 @@ def on_grading_end(self, packet):

finished_submission(submission)

event.post('sub_%s' % submission.id_secret, {
'type': 'grading-end',
'time': time,
'memory': memory,
'points': float(points),
'total': float(problem.points),
'result': submission.result,
})
event.post('sub_%s' % submission.id_secret, {'type': 'grading-end'})
if hasattr(submission, 'contest'):
participation = submission.contest.participation
event.post('contest_%d' % participation.contest_id, {'type': 'update'})
Expand All @@ -444,10 +438,7 @@ def on_compile_error(self, packet):
self._free_self(packet)

if Submission.objects.filter(id=packet['submission-id']).update(status='CE', result='CE', error=packet['log']):
event.post('sub_%s' % Submission.get_id_secret(packet['submission-id']), {
'type': 'compile-error',
'log': packet['log'],
})
event.post('sub_%s' % Submission.get_id_secret(packet['submission-id']), {'type': 'compile-error'})
self._post_update_submission(packet['submission-id'], 'compile-error', done=True)
json_log.info(self._make_json_log(packet, action='compile-error', log=packet['log'],
finish=True, result='CE'))
Expand Down Expand Up @@ -565,6 +556,12 @@ def on_test_case(self, packet, max_feedback=SubmissionTestCase._meta.get_field('
runtime_version=result.get('runtime-version', ''),
))

SubmissionTestCase.objects.bulk_create(bulk_test_case_updates)

data = self._get_submission_cache(id)
if data['problem__testcase_result_visibility_mode'] != ProblemTestcaseResultAccess.ALL_TEST_CASE:
return

do_post = True

if id in self.update_counter:
Expand All @@ -580,14 +577,9 @@ def on_test_case(self, packet, max_feedback=SubmissionTestCase._meta.get_field('
self.update_counter[id] = (1, time.monotonic())

if do_post:
event.post('sub_%s' % Submission.get_id_secret(id), {
'type': 'test-case',
'id': max_position,
})
event.post('sub_%s' % Submission.get_id_secret(id), {'type': 'test-case'})
self._post_update_submission(id, state='test-case')

SubmissionTestCase.objects.bulk_create(bulk_test_case_updates)

def on_malformed(self, packet):
logger.error('%s: Malformed packet: %s', self.name, packet)
json_log.exception(self._make_json_log(sub=self._working, info='malformed json packet'))
Expand Down Expand Up @@ -627,16 +619,18 @@ def _make_json_log(self, packet=None, sub=None, **kwargs):
data.update(kwargs)
return json.dumps(data)

def _post_update_submission(self, id, state, done=False):
if self._submission_cache_id == id:
data = self._submission_cache
else:
self._submission_cache = data = Submission.objects.filter(id=id).values(
'problem__is_public', 'contest_object_id',
def _get_submission_cache(self, id):
if self._submission_cache_id != id:
self._submission_cache = Submission.objects.filter(id=id).values(
'problem__is_public', 'problem__testcase_result_visibility_mode', 'contest_object_id',
'user_id', 'problem_id', 'status', 'language__key',
).get()
self._submission_cache_id = id

return self._submission_cache

def _post_update_submission(self, id, state, done=False):
data = self._get_submission_cache(id)
if data['problem__is_public']:
event.post('submissions', {
'type': 'done-submission' if done else 'update-submission',
Expand Down

0 comments on commit 1ce5bb9

Please sign in to comment.