From 531f5d1e4fcbc3e3f1801b272935affbed0acd90 Mon Sep 17 00:00:00 2001 From: Simon L Date: Fri, 3 Nov 2023 11:47:12 +0100 Subject: [PATCH 1/2] fix semaphore guarding Signed-off-by: Simon L --- lib/private/Preview/Generator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index 4a1270fa4a60b..d936f1d65ad2a 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -244,7 +244,7 @@ public static function guardWithSemaphore(int $semId, int $concurrency) { * @return bool */ public static function unguardWithSemaphore($semId): bool { - if (!is_resource($semId) || !extension_loaded('sysvsem')) { + if ($semId === false || get_class($semId) !== 'SysvSemaphore' || !extension_loaded('sysvsem')) { return false; } return sem_release($semId); From b681cf735a29b6ae25e03813b2efe77e4fe25613 Mon Sep 17 00:00:00 2001 From: Simon L Date: Fri, 3 Nov 2023 15:27:17 +0100 Subject: [PATCH 2/2] address review Signed-off-by: Simon L --- build/psalm-baseline.xml | 7 ------- lib/private/Preview/Generator.php | 8 ++++---- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 8a2c728ab5b4b..273c7ef470946 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -3075,14 +3075,7 @@ $maxPreviewImage - $semId - - $sem - - - false|resource - null|string diff --git a/lib/private/Preview/Generator.php b/lib/private/Preview/Generator.php index d936f1d65ad2a..958f58e2a0179 100644 --- a/lib/private/Preview/Generator.php +++ b/lib/private/Preview/Generator.php @@ -221,7 +221,7 @@ public function generatePreviews(File $file, array $specifications, $mimeType = * * @param int $semId * @param int $concurrency - * @return false|resource the semaphore on success or false on failure + * @return false|\SysvSemaphore the semaphore on success or false on failure */ public static function guardWithSemaphore(int $semId, int $concurrency) { if (!extension_loaded('sysvsem')) { @@ -240,11 +240,11 @@ public static function guardWithSemaphore(int $semId, int $concurrency) { /** * Releases the semaphore acquired from {@see Generator::guardWithSemaphore()}. * - * @param resource|bool $semId the semaphore identifier returned by guardWithSemaphore + * @param false|\SysvSemaphore $semId the semaphore identifier returned by guardWithSemaphore * @return bool */ - public static function unguardWithSemaphore($semId): bool { - if ($semId === false || get_class($semId) !== 'SysvSemaphore' || !extension_loaded('sysvsem')) { + public static function unguardWithSemaphore(false|\SysvSemaphore $semId): bool { + if ($semId === false || !($semId instanceof \SysvSemaphore)) { return false; } return sem_release($semId);