1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

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
This commit is contained in:
Andre Klapper 2024-01-17 16:13:11 +01:00
parent 5de10185ce
commit 7702772b2b

View file

@ -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;
}