From 9a204ad4556f84b948c2d0eea329bb8e0fe1986b Mon Sep 17 00:00:00 2001 From: Mauro Cassani Date: Wed, 1 Apr 2026 18:25:32 +0200 Subject: [PATCH 1/4] Implemented getRealFilesCount method in UploadHandler --- docker | 2 +- lib/View/fileupload/UploadHandler.php | 34 ++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/docker b/docker index fd856c2e02..dc9daafd0f 160000 --- a/docker +++ b/docker @@ -1 +1 @@ -Subproject commit fd856c2e02bba8a2994d83f5a3b401b982ea9395 +Subproject commit dc9daafd0fb5f7bab98e0a7ec9f6e2f7801d0c78 diff --git a/lib/View/fileupload/UploadHandler.php b/lib/View/fileupload/UploadHandler.php index 1f6349c82c..1036129a19 100644 --- a/lib/View/fileupload/UploadHandler.php +++ b/lib/View/fileupload/UploadHandler.php @@ -170,7 +170,7 @@ protected function validate(string $uploaded_file, stdClass $file, string $error } if (is_int($this->options['max_number_of_files']) && ( - count($this->get_file_objects()) >= $this->options['max_number_of_files']) + $this->getRealFilesCount() >= $this->options['max_number_of_files']) ) { $file->error = 'Too many files uploaded. Please remove this file to continue.'; @@ -205,6 +205,38 @@ protected function validate(string $uploaded_file, stdClass $file, string $error return true; } + /** + * Counts the number of real files excluding those with specific patterns in their names. + * + * @return int The number of real files that do not match the predefined exclusion pattern. + */ + private function getRealFilesCount(): int + { + $files = $this->get_file_objects(); + + if (empty($files)) { + return 0; + } + + $count = 0; + + // remove sha1 + foreach ($files as $file) { + + // Exclude files with sha1 in the name. + // Ex. 70a1af62ebce284ccaa4ab0dc8a37afb5b4cd296_da39a3ee5e6b4b0d3255bfef95601890afd80709|en-US + $pattern = '/^([a-f0-9]{40}(?:_[a-f0-9]{40})?)\|([a-z]{2}(?:-[A-Z]{2})?)$/'; + + if (preg_match($pattern, $file->name, $matches)) { + continue; + } + + $count++; + } + + return $count; + } + protected function up_count_name_callback($matches): string { $index = isset($matches[1]) ? intval($matches[1]) + 1 : 1; From 696f11f00e1214cff6cc956a82ab480587362a7f Mon Sep 17 00:00:00 2001 From: Mauro Cassani Date: Thu, 2 Apr 2026 10:10:08 +0200 Subject: [PATCH 2/4] refined regex --- lib/View/fileupload/UploadHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/View/fileupload/UploadHandler.php b/lib/View/fileupload/UploadHandler.php index 1036129a19..e7c92ad393 100644 --- a/lib/View/fileupload/UploadHandler.php +++ b/lib/View/fileupload/UploadHandler.php @@ -225,7 +225,7 @@ private function getRealFilesCount(): int // Exclude files with sha1 in the name. // Ex. 70a1af62ebce284ccaa4ab0dc8a37afb5b4cd296_da39a3ee5e6b4b0d3255bfef95601890afd80709|en-US - $pattern = '/^([a-f0-9]{40}(?:_[a-f0-9]{40})?)\|([a-z]{2}(?:-[A-Z]{2})?)$/'; + $pattern = '/^[a-f0-9]{40}_[a-f0-9]{40}\|[a-zA-Z]{2,3}(?:-[a-zA-Z]{4})?(?:-(?:[a-zA-Z]{2}|[0-9]{3}))?(?:-[a-zA-Z0-9]+)*$/'; if (preg_match($pattern, $file->name, $matches)) { continue; From 87b6a1a9790df00e248d6a146733a1bd38a07f06 Mon Sep 17 00:00:00 2001 From: Mauro Cassani Date: Tue, 28 Apr 2026 12:17:24 +0200 Subject: [PATCH 3/4] fix: resolved conflicts --- docker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker b/docker index dc9daafd0f..b0553a128b 160000 --- a/docker +++ b/docker @@ -1 +1 @@ -Subproject commit dc9daafd0fb5f7bab98e0a7ec9f6e2f7801d0c78 +Subproject commit b0553a128b136e615216d555e49ba0d7882f5b8b From 7cf75fe2a68addb9e4145485874d2055b6aab484 Mon Sep 17 00:00:00 2001 From: Mauro Cassani Date: Tue, 28 Apr 2026 12:21:50 +0200 Subject: [PATCH 4/4] feat: resolved conflict --- docker | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker b/docker index b0553a128b..1be999a369 160000 --- a/docker +++ b/docker @@ -1 +1 @@ -Subproject commit b0553a128b136e615216d555e49ba0d7882f5b8b +Subproject commit 1be999a369607ce44b33dfe760f56980fc69f93e