Skip to content

Commit cc91be3

Browse files
Account for non-xml submission objects (#2663)
When given a non-xml submission file, catch the exception of the bad submission and only reject the submission of the Validate setting is enabled. Fixes: #2662 --------- Co-authored-by: William Allen <[email protected]>
1 parent 4903cea commit cc91be3

File tree

4 files changed

+34
-33
lines changed

4 files changed

+34
-33
lines changed

app/Http/Controllers/SubmissionController.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,28 @@ private function submitProcess(): Response
136136

137137
// Figure out what type of XML file this is.
138138
$stored_filename = 'inbox/' . $filename;
139-
$xml_info = SubmissionUtils::get_xml_type(fopen(Storage::path($stored_filename), 'r'), $stored_filename);
140-
141-
// If validation is enabled and if this file has a corresponding schema, validate it
142-
$validation_errors = $xml_info['xml_handler']::validate(storage_path('app/' . $stored_filename));
143-
if (count($validation_errors) > 0) {
144-
$error_string = implode(PHP_EOL, $validation_errors);
145-
146-
// We always log validation failures, but we only send messages back to the client if configured to do so
147-
Log::warning("Submission validation failed for file '$filename':" . PHP_EOL);
139+
$xml_info = [];
140+
try {
141+
$xml_info = SubmissionUtils::get_xml_type(fopen(Storage::path($stored_filename), 'r'), $stored_filename);
142+
} catch (BadSubmissionException $e) {
143+
$xml_info['xml_handler'] = '';
144+
$message = "Could not determine submission file type for: '{$stored_filename}'";
145+
Log::warning($message);
148146
if ((bool) config('cdash.validate_xml_submissions') === true) {
149-
abort(400, "XML validation failed: rejected file $filename:" . PHP_EOL . $error_string);
147+
abort(400, $message);
148+
}
149+
}
150+
if ($xml_info['xml_handler'] !== '') {
151+
// If validation is enabled and if this file has a corresponding schema, validate it
152+
$validation_errors = $xml_info['xml_handler']::validate(storage_path('app/' . $stored_filename));
153+
if (count($validation_errors) > 0) {
154+
$error_string = implode(PHP_EOL, $validation_errors);
155+
156+
// We always log validation failures, but we only send messages back to the client if configured to do so
157+
Log::warning("Submission validation failed for file '$filename':" . PHP_EOL);
158+
if ((bool) config('cdash.validate_xml_submissions') === true) {
159+
abort(400, "XML validation failed: rejected file $filename:" . PHP_EOL . $error_string);
160+
}
150161
}
151162
}
152163

app/Jobs/ProcessSubmission.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use AbstractSubmissionHandler;
66
use ActionableBuildInterface;
7-
use App\Exceptions\BadSubmissionException;
87
use App\Models\SuccessfulJob;
98
use App\Utils\UnparsedSubmissionProcessor;
109
use BuildPropertiesJSONHandler;
@@ -133,8 +132,6 @@ private function requeueSubmissionFile($buildid): bool
133132
* Execute the job.
134133
*
135134
* @return void
136-
*
137-
* @throws BadSubmissionException
138135
*/
139136
public function handle()
140137
{
@@ -199,7 +196,6 @@ public function failed(Throwable $exception): void
199196
* This method could be running on a worker that is either remote or local, so it accepts
200197
* a file handle or a filename that it can query the CDash API for.
201198
*
202-
* @throws BadSubmissionException
203199
**/
204200
private function doSubmit($filename, $projectid, $buildid = null, $expected_md5 = ''): AbstractSubmissionHandler|UnparsedSubmissionProcessor|false
205201
{

app/cdash/include/ctestparser.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ function parse_put_submission($filehandler, $projectid, $expected_md5, ?int $bui
159159

160160
/**
161161
* Main function to parse the incoming xml from ctest
162-
*
163-
* @throws BadSubmissionException
164162
*/
165163
function ctest_parse($filehandle, string $filename, $projectid, $expected_md5 = '', ?int $buildid = null): AbstractSubmissionHandler|false
166164
{
@@ -185,9 +183,20 @@ function ctest_parse($filehandle, string $filename, $projectid, $expected_md5 =
185183

186184
$Project = new Project();
187185
$Project->Id = $projectid;
188-
186+
$xml_info = [];
189187
// Figure out what type of XML file this is.
190-
$xml_info = SubmissionUtils::get_xml_type($filehandle, $filename);
188+
try {
189+
$xml_info = SubmissionUtils::get_xml_type($filehandle, $filename);
190+
} catch (BadSubmissionException $e) {
191+
$xml_info['file_handle'] = $filehandle;
192+
$xml_info['xml_handler'] = null;
193+
$xml_info['xml_type'] = '';
194+
$message = "Could not determine submission file type for: '{$filename}'";
195+
Log::warning($message);
196+
if ((bool) config('cdash.validate_xml_submissions') === true) {
197+
abort(400, $message);
198+
}
199+
}
191200
$filehandle = $xml_info['file_handle'];
192201
$handler_ref = $xml_info['xml_handler'];
193202
$file = $xml_info['xml_type'];

phpstan-baseline.neon

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14012,21 +14012,6 @@ parameters:
1401214012
count: 1
1401314013
path: app/cdash/include/ctestparser.php
1401414014

14015-
-
14016-
message: "#^Parameter \\#1 \\$stream of function feof expects resource, mixed given\\.$#"
14017-
count: 1
14018-
path: app/cdash/include/ctestparser.php
14019-
14020-
-
14021-
message: "#^Parameter \\#1 \\$stream of function fread expects resource, mixed given\\.$#"
14022-
count: 2
14023-
path: app/cdash/include/ctestparser.php
14024-
14025-
-
14026-
message: "#^Parameter \\#1 \\$stream of function rewind expects resource, mixed given\\.$#"
14027-
count: 1
14028-
path: app/cdash/include/ctestparser.php
14029-
1403014015
-
1403114016
message: "#^Parameter \\#2 \\$data of function xml_parse expects string, string\\|false given\\.$#"
1403214017
count: 2

0 commit comments

Comments
 (0)