Page MenuHomePhorge

PHP 8.1 "implicit conversion from float to int" exception on certain avatar colors which blocks rendering user pages
Closed, ResolvedPublic

Description

  1. PHP 8.2.5; Phorge at ac4c95169973e742ea768ebd103bb2142c3bdc7d
  2. Create several new user accounts via http://phorge.localhost/people/new/standard/ (either disable Send "Welcome to Phorge" email checkbox, or apply D25208)
  3. Go to their user pages at http://phorge.localhost/p/username/
  4. Some of the user pages display exceptions like:
[2023-05-09 18:27:33] EXCEPTION: (RuntimeException) Implicit conversion from float 178.5 to int loses precision at [<arcanist>/src/error/PhutilErrorHandler.php:261]
arcanist(head=renderDashboardTabPanelContent, ref.master=d47289622650, ref.renderDashboardTabPanelContent=d47289622650), phorge(head=master, ref.master=ac4c95169973)
  #0 <#2> PhutilErrorHandler::handleError(integer, string, string, integer) called at [<phorge>/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:192]
  #1 <#2> PhabricatorFilesComposeAvatarBuiltinFile::rgba2gd(array) called at [<phorge>/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:148]
  #2 <#2> PhabricatorFilesComposeAvatarBuiltinFile::composeImage(string, string, array) called at [<phorge>/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:28]
  #3 <#2> PhabricatorFilesComposeAvatarBuiltinFile::updateUser(PhabricatorUser) called at [<phorge>/src/applications/people/cache/PhabricatorUserProfileImageCacheType.php:50]
  #4 <#2> PhabricatorUserProfileImageCacheType::newValueForUsers(string, array) called at [<phorge>/src/applications/people/query/PhabricatorPeopleQuery.php:606]
  #5 <#2> PhabricatorPeopleQuery::fillUserCaches(array) called at [<phorge>/src/applications/people/query/PhabricatorPeopleQuery.php:436]
  #6 <#2> PhabricatorPeopleQuery::rebuildAvailabilityCache(array) called at [<phorge>/src/applications/people/query/PhabricatorPeopleQuery.php:197]
  #7 <#2> PhabricatorPeopleQuery::didFilterPage(array) called at [<phorge>/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php:288]
  #8 <#2> PhabricatorPolicyAwareQuery::execute() called at [<phorge>/src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php:180]
  #9 <#2> PhabricatorPolicyAwareQuery::executeOne() called at [<phorge>/src/applications/people/controller/PhabricatorPeopleProfileViewController.php:19]
  #10 <#2> PhabricatorPeopleProfileViewController::handleRequest(AphrontRequest) called at [<phorge>/src/aphront/configuration/AphrontApplicationConfiguration.php:284]
  #11 phlog(RuntimeException) called at [<phorge>/src/aphront/handler/PhabricatorDefaultRequestExceptionHandler.php:41]
  #12 PhabricatorDefaultRequestExceptionHandler::handleRequestThrowable(AphrontRequest, RuntimeException) called at [<phorge>/src/aphront/configuration/AphrontApplicationConfiguration.php:751]
  #13 AphrontApplicationConfiguration::handleThrowable(RuntimeException) called at [<phorge>/src/aphront/configuration/AphrontApplicationConfiguration.php:296]
  #14 AphrontApplicationConfiguration::processRequest(AphrontRequest, PhutilDeferredLog, AphrontPHPHTTPSink, MultimeterControl) called at [<phorge>/src/aphront/configuration/AphrontApplicationConfiguration.php:203]
  #15 AphrontApplicationConfiguration::runHTTPRequest(AphrontPHPHTTPSink) called at [<phorge>/webroot/index.php:35]

Since PHP 8.1 conversion from float to int should be explicit.

According to phlog, this is due to the alpha channel value. The r, g, b values seem to always be integers.
Obviously this cannot always be triggered when creating the default user avatar, as the alpha value can sometimes become an integer:

[2023-05-09 18:34:35] PHLOG: '$a = $rgba[3]: 0.7' at [/var/www/html/phorge/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:194]
[2023-05-09 18:34:35] PHLOG: '$a = (1 - $a) * 255: 76.5' at [/var/www/html/phorge/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:196]
[2023-05-09 18:37:00] PHLOG: '$a = $rgba[3]: 0.3' at [/var/www/html/phorge/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:194]
[2023-05-09 18:37:00] PHLOG: '$a = (1 - $a) * 255: 178.5' at [/var/www/html/phorge/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:196]
[2023-05-09 18:37:14] PHLOG: '$a = $rgba[3]: 0.4' at [/var/www/html/phorge/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:194]
[2023-05-09 18:37:14] PHLOG: '$a = (1 - $a) * 255: 153' at [/var/www/html/phorge/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:196]

After applying round() on the $a value and using phlog, creating a few users worked as expected:

[2023-05-09 18:46:30] PHLOG: '$a init: 0.7' at [/var/www/html/phorge/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:191]
[2023-05-09 18:46:30] PHLOG: '$a comp: 76.5' at [/var/www/html/phorge/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:193]
[2023-05-09 18:46:30] PHLOG: '$a comp rounded: 77' at [/var/www/html/phorge/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:196]
[2023-05-09 18:47:09] PHLOG: '$a init: 0' at [/var/www/html/phorge/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:191]
[2023-05-09 18:47:09] PHLOG: '$a comp: 255' at [/var/www/html/phorge/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:193]
[2023-05-09 18:47:09] PHLOG: '$a comp rounded: 255' at [/var/www/html/phorge/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:196]
[2023-05-09 18:47:46] PHLOG: '$a init: 0.3' at [/var/www/html/phorge/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:191]
[2023-05-09 18:47:46] PHLOG: '$a comp: 178.5' at [/var/www/html/phorge/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:193]
[2023-05-09 18:47:46] PHLOG: '$a comp rounded: 179' at [/var/www/html/phorge/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php:196]