From f41fe2ecd5421702661c9d3029daa164b0375015 Mon Sep 17 00:00:00 2001 From: Git'Fellow <12234510+solracsf@users.noreply.github.com> Date: Fri, 27 Mar 2026 18:57:19 +0100 Subject: [PATCH] fix(chunkedUploads): Ensure max parallel count is at least 1 Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com> Signed-off-by: Josh --- .../files/lib/Service/ChunkedUploadConfig.php | 2 +- .../tests/Service/ChunkedUploadConfigTest.php | 50 +++++++++++++++++++ config/config.sample.php | 2 +- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 apps/files/tests/Service/ChunkedUploadConfigTest.php diff --git a/apps/files/lib/Service/ChunkedUploadConfig.php b/apps/files/lib/Service/ChunkedUploadConfig.php index 29661750f8b07..0bf83b649c7f9 100644 --- a/apps/files/lib/Service/ChunkedUploadConfig.php +++ b/apps/files/lib/Service/ChunkedUploadConfig.php @@ -25,6 +25,6 @@ public static function setMaxChunkSize(int $maxChunkSize): void { } public static function getMaxParallelCount(): int { - return Server::get(IConfig::class)->getSystemValueInt(self::KEY_MAX_PARALLEL_COUNT, 5); + return max(1, Server::get(IConfig::class)->getSystemValueInt(self::KEY_MAX_PARALLEL_COUNT, 5)); } } diff --git a/apps/files/tests/Service/ChunkedUploadConfigTest.php b/apps/files/tests/Service/ChunkedUploadConfigTest.php new file mode 100644 index 0000000000000..9b0f51f2d26c0 --- /dev/null +++ b/apps/files/tests/Service/ChunkedUploadConfigTest.php @@ -0,0 +1,50 @@ +config = $this->createMock(IConfig::class); + $this->overwriteService(IConfig::class, $this->config); + } + + protected function tearDown(): void { + $this->restoreAllServices(); + parent::tearDown(); + } + + public static function dataGetMaxParallelCount(): array { + return [ + 'configured positive value' => [3, 3], + 'boundary minimum' => [1, 1], + 'zero becomes one' => [0, 1], + 'negative becomes one' => [-2, 1], + 'large value passes through' => [100, 100], + ]; + } + + #[DataProvider('dataGetMaxParallelCount')] + public function testGetMaxParallelCount(int $configuredValue, int $expectedValue): void { + $this->config->expects($this->once()) + ->method('getSystemValueInt') + ->with('files.chunked_upload.max_parallel_count', 5) + ->willReturn($configuredValue); + + $this->assertSame($expectedValue, ChunkedUploadConfig::getMaxParallelCount()); + } +} diff --git a/config/config.sample.php b/config/config.sample.php index 2a886f687a3c6..c4162a69a3b22 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -2798,7 +2798,7 @@ /** * Maximum number of chunks uploaded in parallel during chunked uploads. Higher * counts increase throughput but consume more server resources, with diminishing - * returns. + * returns. Value must be a positive integer. * * Defaults to ``5`` */