diff --git a/core/Migrations/Version34000Date20260318095645.php b/core/Migrations/Version34000Date20260318095645.php new file mode 100644 index 00000000000..8be6dfc9122 --- /dev/null +++ b/core/Migrations/Version34000Date20260318095645.php @@ -0,0 +1,41 @@ +hasTable('jobs')) { + $table = $schema->getTable('jobs'); + $argumentColumn = $table->getColumn('argument'); + + if ($argumentColumn->getType() !== Type::getType(Types::TEXT)) { + $argumentColumn->setType(Type::getType(Types::TEXT)); + return $schema; + } + } + + return null; + } +} diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php index ab7a1981419..2ec8f663b3f 100644 --- a/lib/private/BackgroundJob/JobList.php +++ b/lib/private/BackgroundJob/JobList.php @@ -26,6 +26,8 @@ use function min; use function strlen; class JobList implements IJobList { + public const MAX_ARGUMENT_JSON_LENGTH = 32000; + /** @var array */ protected array $alreadyVisitedParallelBlocked = []; @@ -47,8 +49,8 @@ class JobList implements IJobList { $class = ($job instanceof IJob) ? get_class($job) : $job; $argumentJson = json_encode($argument); - if (strlen($argumentJson) > 4000) { - throw new \InvalidArgumentException('Background job arguments can\'t exceed 4000 characters (json encoded)'); + if (strlen($argumentJson) > self::MAX_ARGUMENT_JSON_LENGTH) { + throw new \InvalidArgumentException('Background job arguments can\'t exceed ' . self::MAX_ARGUMENT_JSON_LENGTH . ' characters (json encoded)'); } $query = $this->connection->getQueryBuilder(); diff --git a/tests/lib/BackgroundJob/JobListTest.php b/tests/lib/BackgroundJob/JobListTest.php index affd97a238a..df3cd451be4 100644 --- a/tests/lib/BackgroundJob/JobListTest.php +++ b/tests/lib/BackgroundJob/JobListTest.php @@ -99,6 +99,24 @@ class JobListTest extends TestCase { $this->assertEquals($existingJobs, $jobs); } + public function testAddAcceptsArgumentUnderMaxLength(): void { + $argument = str_repeat('a', $this->instance::MAX_ARGUMENT_JSON_LENGTH - 100); + $job = new TestJob(); + $this->assertFalse($this->instance->has($job, $argument)); + $this->instance->add($job, $argument); + + $this->assertTrue($this->instance->has($job, $argument)); + } + + public function testAddRejectsArgumentAboveMaxLength(): void { + $argument = str_repeat('a', $this->instance::MAX_ARGUMENT_JSON_LENGTH + 100); + + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Background job arguments can\'t exceed ' . $this->instance::MAX_ARGUMENT_JSON_LENGTH . ' characters (json encoded)'); + + $this->instance->add(new TestJob(), $argument); + } + #[DataProvider('argumentProvider')] public function testRemoveDifferentArgument(mixed $argument): void { $existingJobs = $this->getAllSorted(); diff --git a/version.php b/version.php index 22b0aa6d67a..76e3e67166d 100644 --- a/version.php +++ b/version.php @@ -9,7 +9,7 @@ // between betas, final and RCs. This is _not_ the public version number. Reset minor/patch level // when updating major/minor version number. -$OC_Version = [33, 0, 0, 16]; +$OC_Version = [33, 0, 0, 17]; // The human-readable string $OC_VersionString = '33.0.0';