Page MenuHomePhorge

Fix PHP 8.1 "strlen(null)" exceptions to render the Account Creation page
ClosedPublic

Authored by aklapper on Apr 27 2023, 07:51.

Details

Summary

Fix numerous PHP 8.1 "strlen(null)" exceptions which block rendering the initial Account
Creation page in a fresh Phorge installation.

The strlen() was used in Phabricator to check if a generic value was a non-empty string.
For this reason, Phorge adopts phutil_nonempty_string() that checks that.

Note: this may highlight other absurd input values that might be worth correcting
instead of just ignoring. If your phutil_nonempty_string() throws an exception, just
report it to Phorge to evaluate and fix together that specific corner case.

Closes T15279

Test Plan

After these code changes the account creation page got displayed (though without CSS and JS).

Diff Detail

Repository
rP Phorge
Branch
arcpatch-D25137_2
Lint
Lint Passed
Unit
Test Failures
Build Status
Buildable 278
Build 278: arc lint + arc unit

Unit TestsFailed

TimeTest
214 msPhabricatorAuthPasswordTestCase::testPasswordEngine
EXCEPTION (RuntimeException): Implicit conversion from float 76.50000000000001 to int loses precision #0 /var/www/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php(192): PhutilErrorHandler::handleError(8192, '...', '...', 192) #1 /var/www/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php(148): PhabricatorFilesComposeAvatarBuiltinFile::rgba2gd(Array)
166 msPhabricatorAuthPasswordTestCase::testPasswordUpgrade
EXCEPTION (RuntimeException): Implicit conversion from float 178.5 to int loses precision #0 /var/www/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php(192): PhutilErrorHandler::handleError(8192, '...', '...', 192) #1 /var/www/phorge/src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php(148): PhabricatorFilesComposeAvatarBuiltinFile::rgba2gd(Array)
423 msPhabricatorAccessControlTestCase::testControllerAccessControls
59 assertions passed.
257 msPhabricatorAphrontViewTestCase::testHasChildren
6 assertions passed.
256 msPhabricatorApplicationTestCase::testGetAllApplications
1 assertion passed.
View Full Test Results (2 Failed · 17 Passed)

Event Timeline

Note that this has some inevitable overlap with D25132.

src/applications/auth/controller/PhabricatorAuthRegisterController.php
21

✅ The input value is probably safe to be assumed as string or NULL since it comes from $request->getURIData('akey')

src/applications/base/controller/PhabricatorController.php
77

✅ The input value is probably safe to be assumed as string or NULL

src/applications/config/check/PhabricatorDaemonsSetupCheck.php
56 ↗(On Diff #534)

✅ The input value is safe to be assumed as string or NULL

src/view/page/PhabricatorStandardPageView.php
183 ↗(On Diff #534)

This returns a string

191 ↗(On Diff #534)

✅ The input value is probably safe to be assumed as string or NULL

src/view/page/menu/PhabricatorMainMenuView.php
336 ↗(On Diff #534)

✅ The input value is safe to be assumed as string or NULL

./src/applications/config/custom/PhabricatorCustomLogoConfigType.php
public static function getLogoWordmark() {
  $logo = PhabricatorEnv::getEnvConfig('ui.logo'); // this can return NULL or an array
  return idx($logo, 'wordmarkText'); // this can return a string or NULL
}
valerio.bozzolan added inline comments.
src/view/form/control/AphrontFormControl.php
175

The problem with if($error) is that it discards errors message like "0" and Evan is sad.

Probably this is a good example for phutil_nonempty_scalar() since it accepts booleans and other stuff. But we need to merge this before:

D25117: phutil_nonempty_scalar(): don't throw when receiving a boolean scalar

@avivey what do you think about?

Thanks. I have a very small concern on AphrontFormControl.php:50 but really anything important. A simple if is probably just elegant in that case since the string "0" or the number 0 are not useful error messages that should be shown to a frontend.

I start accepting this as O1 since such a severe crash in PHP8.1 doesn't justify not trying to manage it as best we can, and you did it.

sgtm

src/applications/auth/controller/PhabricatorAuthRegisterController.php
247

✅ It's OK to assume a username as string or as NULL (default). Alien values will be reported and this is OK.

249

✅ It's really OK to assume a username as string or as NULL (default). Alien values will be reported and this is OK.

src/view/form/control/AphrontFormControl.php
190

✅ The input value is probably safe to be assumed as string or NULL. Alien values will be reported and that is OK.

I checked 30+ usages and the label is probably always a raw string containing HTML for example and I have not noticed objects with toString() methods.

Average usage example:

->setLabel(pht('Subscribers'))
206

✅ The input value is probably safe to be assumed as string or NULL. Alien values will be reported and that is OK.

I checked 30+ usages and the caption is always a raw string containing HTML for example and I have not noticed objects with toString() methods.

Average usage example:

->setCaption(
  pht('Example: %s', phutil_tag('tt', array(), 'JIS-3, JIS-9'))))
This revision is now accepted and ready to land.Apr 29 2023, 08:52
This revision was landed with ongoing or failed builds.Apr 29 2023, 19:55
This revision was automatically updated to reflect the committed changes.