Skip to content

Commit a1550bf

Browse files
committed
fix(upload): validate file size before FilenameValidator in FileUploadHelper
The FilenameValidator check calls \OCP\Server::get() which has no DI container in unit-test context and throws an unexpected exception. Because that check came before the size check, the \OCP\Util::uploadLimit() branch was never reached, @Unlink was never called, and the temp file survived – breaking testValidateUploadedFileTooBig. Moving the size check earlier also makes semantic sense: rejecting oversized files is cheap and should happen before any filename-policy evaluation. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent a9e38fb commit a1550bf

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

lib/Helper/FileUploadHelper.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ public function validateUploadedFile(array $uploadedFile): void {
3838
throw new InvalidArgumentException($this->l10n->t('Invalid file provided'));
3939
}
4040

41-
$validator = \OCP\Server::get(FilenameValidator::class);
42-
if ($validator->isForbidden($uploadedFile['tmp_name'])) {
41+
if ($uploadedFile['size'] > \OCP\Util::uploadLimit()) {
4342
@unlink($uploadedFile['tmp_name']);
44-
throw new InvalidArgumentException($this->l10n->t('Invalid file provided'));
43+
throw new InvalidArgumentException($this->l10n->t('File is too big'));
4544
}
4645

47-
if ($uploadedFile['size'] > \OCP\Util::uploadLimit()) {
46+
$validator = \OCP\Server::get(FilenameValidator::class);
47+
if ($validator->isForbidden($uploadedFile['tmp_name'])) {
4848
@unlink($uploadedFile['tmp_name']);
49-
throw new InvalidArgumentException($this->l10n->t('File is too big'));
49+
throw new InvalidArgumentException($this->l10n->t('Invalid file provided'));
5050
}
5151
}
5252

0 commit comments

Comments
 (0)