From 7702772b2b86d833414a884d459ecd90ff9d2f05 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Wed, 17 Jan 2024 16:13:11 +0100 Subject: [PATCH] preg_match() null exception setting custom user profile image with empty files.viewable-mime-types Summary: When `files.viewable-mime-types` is not set, `getViewableMimeType()` passes `null` to `preg_match()` which is deprecated behavior since PHP 8.1. Only call `preg_match()` when there are some MIME types to compare. ``` ERROR 8192: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated at [/var/www/html/phorge/phorge/src/applications/files/storage/PhabricatorFile.php:974] ``` Closes T15710 Test Plan: Go to a user profile and try to upload a custom profile picture in BMP format. Reviewers: O1 Blessed Committers, speck Reviewed By: O1 Blessed Committers, speck Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15710 Differential Revision: https://we.phorge.it/D25516 --- src/applications/files/storage/PhabricatorFile.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/applications/files/storage/PhabricatorFile.php b/src/applications/files/storage/PhabricatorFile.php index 6782a5a90e..53af38a33b 100644 --- a/src/applications/files/storage/PhabricatorFile.php +++ b/src/applications/files/storage/PhabricatorFile.php @@ -971,10 +971,13 @@ final class PhabricatorFile extends PhabricatorFileDAO // warns you if you don't have complete support. $matches = null; - $ok = preg_match( - '@^image/(gif|png|jpe?g)@', - $this->getViewableMimeType(), - $matches); + $ok = false; + if ($this->getViewableMimeType() !== null) { + $ok = preg_match( + '@^image/(gif|png|jpe?g)@', + $this->getViewableMimeType(), + $matches); + } if (!$ok) { return false; }