From d80dad42a34879d847e68d93985dff3e365721f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 14 Jun 2022 10:32:36 +0200 Subject: [PATCH 1/6] Replace opis/closure by laravel/serializable-closure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- 3rdparty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty b/3rdparty index 82f352b055e..02403021310 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit 82f352b055efce690ffc533d68c08f77f734fafc +Subproject commit 02403021310540a848eb2385e979fcc0563ee730 From a810b213733585a12d22f3e94bfb4e1fa3cb3f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 14 Jun 2022 10:58:24 +0200 Subject: [PATCH 2/6] Replace opis/closure with laravel/serializable-closure in code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Command/ClosureJob.php | 2 +- lib/private/Command/CommandJob.php | 2 +- lib/private/Command/CronBus.php | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/private/Command/ClosureJob.php b/lib/private/Command/ClosureJob.php index 498fe6d1d96..96b0947129e 100644 --- a/lib/private/Command/ClosureJob.php +++ b/lib/private/Command/ClosureJob.php @@ -26,7 +26,7 @@ use OC\BackgroundJob\QueuedJob; class ClosureJob extends QueuedJob { protected function run($serializedCallable) { - $callable = \Opis\Closure\unserialize($serializedCallable); + $callable = unserialize($serializedCallable)->getClosure(); if (is_callable($callable)) { $callable(); } else { diff --git a/lib/private/Command/CommandJob.php b/lib/private/Command/CommandJob.php index 6fa0c6d7ceb..5b267162c81 100644 --- a/lib/private/Command/CommandJob.php +++ b/lib/private/Command/CommandJob.php @@ -30,7 +30,7 @@ use OCP\Command\ICommand; */ class CommandJob extends QueuedJob { protected function run($serializedCommand) { - $command = \Opis\Closure\unserialize($serializedCommand); + $command = unserialize($serializedCommand); if ($command instanceof ICommand) { $command->handle(); } else { diff --git a/lib/private/Command/CronBus.php b/lib/private/Command/CronBus.php index 89a739617d0..8749ad0bff5 100644 --- a/lib/private/Command/CronBus.php +++ b/lib/private/Command/CronBus.php @@ -26,6 +26,7 @@ namespace OC\Command; use OCP\Command\ICommand; +use Laravel\SerializableClosure\SerializableClosure; class CronBus extends AsyncBus { /** @@ -67,9 +68,9 @@ class CronBus extends AsyncBus { */ private function serializeCommand($command) { if ($command instanceof \Closure) { - return \Opis\Closure\serialize($command); + return serialize(new SerializableClosure($command)); } elseif (is_callable($command) or $command instanceof ICommand) { - return \Opis\Closure\serialize($command); + return serialize($command); } else { throw new \InvalidArgumentException('Invalid command'); } From 95f0cb2a2a8b93041eb7ee2acc25b801d96df232 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 20 Jun 2022 17:34:29 +0200 Subject: [PATCH 3/6] Add a test about unserializing data from opis/closure serialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We need to be able to unserialize data from before upgrade. Signed-off-by: Côme Chilliet --- tests/lib/Command/CronBusTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/lib/Command/CronBusTest.php b/tests/lib/Command/CronBusTest.php index ea610a135d8..100de0a861c 100644 --- a/tests/lib/Command/CronBusTest.php +++ b/tests/lib/Command/CronBusTest.php @@ -47,4 +47,11 @@ class CronBusTest extends AsyncBusTest { $job->execute($this->jobList); } } + + public function testClosureFromPreviousVersion() { + $serializedClosure = 'C:32:"Opis\\Closure\\SerializableClosure":217:{a:5:{s:3:"use";a:0:{}s:8:"function";s:64:"function () {\\Test\\Command\\AsyncBusTest::$lastCommand = \'opis\';}";s:5:"scope";s:24:"Test\\Command\\CronBusTest";s:4:"this";N;s:4:"self";s:32:"0000000027dcfe2f00000000407fa805";}}'; + $this->jobList->add('OC\Command\ClosureJob', $serializedClosure); + $this->runJobs(); + $this->assertEquals('opis', AsyncBusTest::$lastCommand); + } } From dccd80cf7af3705e95f1f69b72e26fb08e3d383d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 21 Jun 2022 10:00:49 +0200 Subject: [PATCH 4/6] Update 3rdparty branch with opis/closure back MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- 3rdparty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty b/3rdparty index 02403021310..b74877c2ca2 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit 02403021310540a848eb2385e979fcc0563ee730 +Subproject commit b74877c2ca2bf1c382b8c46601167ba086f633a7 From 3e94faef06b345ff92d990d033141fed6ef2915a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 21 Jun 2022 10:03:53 +0200 Subject: [PATCH 5/6] Update 3rdparty branch with opis/closure back MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- 3rdparty | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty b/3rdparty index b74877c2ca2..b5f73e95a36 160000 --- a/3rdparty +++ b/3rdparty @@ -1 +1 @@ -Subproject commit b74877c2ca2bf1c382b8c46601167ba086f633a7 +Subproject commit b5f73e95a36edde3bf36bea8c72204692af1a0b5 From d8c419c304ad783d419f77aa03e83ee1adf23efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Tue, 21 Jun 2022 11:33:46 +0200 Subject: [PATCH 6/6] Explicitely only accept closures from our dependencies in ClosureJob MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- lib/private/Command/ClosureJob.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/private/Command/ClosureJob.php b/lib/private/Command/ClosureJob.php index 96b0947129e..5639852e4db 100644 --- a/lib/private/Command/ClosureJob.php +++ b/lib/private/Command/ClosureJob.php @@ -23,10 +23,13 @@ namespace OC\Command; use OC\BackgroundJob\QueuedJob; +use Laravel\SerializableClosure\SerializableClosure as LaravelClosure; +use Opis\Closure\SerializableClosure as OpisClosure; class ClosureJob extends QueuedJob { protected function run($serializedCallable) { - $callable = unserialize($serializedCallable)->getClosure(); + $callable = unserialize($serializedCallable, [LaravelClosure::class, OpisClosure::class]); + $callable = $callable->getClosure(); if (is_callable($callable)) { $callable(); } else {