Skip to content

Commit

Permalink
Fail problem import when multiple validators are specified.
Browse files Browse the repository at this point in the history
Fixes #1843.

While we could in theory wrap the validators ourselves, it is unclear
what to do in case the validators disagree (wrong-answer if exactly one
rejects the submission vs internal-error?), and we leave this up to the
jury to decide on a behavior and write the wrapper script themselves.
  • Loading branch information
meisterT committed Nov 24, 2023
1 parent a6640d5 commit 1014630
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions webapp/src/Service/ImportProblemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,9 @@ public function importZippedProblem(
if (isset($yamlData['validation'])
&& ($yamlData['validation'] == 'custom' ||
$yamlData['validation'] == 'custom interactive')) {
$this->searchAndAddValidator($zip, $messages, $externalId, $yamlData['validation'], $problem);
if (!$this->searchAndAddValidator($zip, $messages, $externalId, $yamlData['validation'], $problem)) {
return null;
}
}

if (isset($yamlData['limits'])) {
Expand Down Expand Up @@ -898,7 +900,7 @@ public function importProblemFromRequest(Request $request, ?int $contestId = nul
];
}

private function searchAndAddValidator(ZipArchive $zip, ?array &$messages, string $externalId, string $validationMode, ?Problem $problem): void
private function searchAndAddValidator(ZipArchive $zip, ?array &$messages, string $externalId, string $validationMode, ?Problem $problem): bool
{
$validatorFiles = [];
for ($i = 0; $i < $zip->numFiles; $i++) {
Expand All @@ -910,6 +912,7 @@ private function searchAndAddValidator(ZipArchive $zip, ?array &$messages, strin
}
if (sizeof($validatorFiles) == 0) {
$messages['danger'][] = 'Custom validator specified but not found.';
return false;
} else {
// File(s) have to share common directory.
$validatorDir = mb_substr($validatorFiles[0], 0, mb_strrpos($validatorFiles[0], '/')) . '/';
Expand All @@ -923,7 +926,8 @@ private function searchAndAddValidator(ZipArchive $zip, ?array &$messages, strin
}
}
if (!$sameDir) {
$messages['warning'][] = 'Found multiple custom output validators.';
$messages['danger'][] = 'Found multiple custom output validators.';
return false;
} else {
$tmpzipfiledir = exec("mktemp -d --tmpdir=" .
$this->dj->getDomjudgeTmpDir(),
Expand Down Expand Up @@ -992,5 +996,6 @@ private function searchAndAddValidator(ZipArchive $zip, ?array &$messages, strin
$messages['info'][] = "Added output validator '$outputValidatorName'.";
}
}
return true;
}
}

0 comments on commit 1014630

Please sign in to comment.