Page MenuHomePhorge

Fix PHP 8.1 "strlen(null)" exception which blocks Working Copy blueprint creation in Drydock
ClosedPublic

Authored by aklapper on May 21 2023, 08:25.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Mar 28, 06:18
Unknown Object (File)
Tue, Mar 26, 06:08
Unknown Object (File)
Sun, Mar 24, 06:46
Unknown Object (File)
Wed, Mar 20, 10:48
Unknown Object (File)
Feb 25 2024, 07:38
Unknown Object (File)
Feb 25 2024, 07:38
Unknown Object (File)
Feb 25 2024, 07:38
Unknown Object (File)
Feb 25 2024, 06:55

Details

Summary

strlen() was used in Phabricator to check if a generic value is a non-empty string.
This behavior is deprecated since PHP 8.1. So, we adopt an explicit cast to string
in order to answer the question "Is this a non-empty string?" without relying on implicit
cast and deprecated things.

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

Closes T15409

Test Plan

Applied this change and afterwards, selecting "Working Copy" on /drydock/blueprint/edit/form/default/ does not show a RuntimeException on strlen() anymore. Instead, it shows a PhutilAggregateException covered in T15408.

Try also creating an integer "Custom Field" in some applications like Maniphest (maniphest.custom-field-definitions)
or in the People component (user.custom-field-definitions) etc., populating the related forms with your usual fuzzy tests.

Diff Detail

Repository
rP Phorge
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Thanks for this troubleshooting and this patch (again) :)

Warning: I was able to reproduce the usual nuclear implosion. I tried to populate a custom integer field from a Maniphest Task from a normal form. I tried that just because the name of this class is about FieldInt so it was a bit suspicious.

Hoping to be useful I will amend our usual replacement

replace phutil_nonempty_string() with just an explicit cast to string to answer the question "is this string non empty?"
so this works with integers as well, without crashes.

Tested, no nuclear implosions

sgtm

This revision is now accepted and ready to land.May 21 2023, 08:53
valerio.bozzolan edited the summary of this revision. (Show Details)
valerio.bozzolan edited the test plan for this revision. (Show Details)