Page MenuHomePhorge

Fix PHP 8.1 "strlen(null)" exceptions which block rendering page of a File
ClosedPublic

Authored by aklapper on May 4 2023, 11:41.
Tags
None
Referenced Files
F3307167: D25186.1743139923.diff
Thu, Mar 27, 05:32
F3306913: D25186.1743134651.diff
Thu, Mar 27, 04:04
F3306911: D25186.1743134604.diff
Thu, Mar 27, 04:03
F3306910: D25186.1743134602.diff
Thu, Mar 27, 04:03
F3306380: D25186.1743127662.diff
Thu, Mar 27, 02:07
F3304560: D25186.1743100289.diff
Wed, Mar 26, 18:31
F3303767: D25186.1743085543.diff
Wed, Mar 26, 14:25
F3302978: D25186.1743074344.diff
Wed, Mar 26, 11:19

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. Phorge adopts phutil_nonempty_string() as a replacement.

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

Closes T15341

Test Plan

Applied these four changes and file page at /F91 finally rendered in web browser.

Diff Detail

Repository
rP Phorge
Branch
uploadFile (branched from master)
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 355
Build 355: arc lint + arc unit

Event Timeline

aklapper requested review of this revision.May 4 2023, 11:41

Thanks for this patch, again (!!!)

I tested this patch, locally, trying to do lot of fuzzy tests. With/withno alternative texts, changing encoding types, etc. I was not able to reproduce any nuclear crash.

Green light

sgtm

src/applications/files/controller/PhabricatorFileViewController.php
314

✅ I verified the above line

The $custom_alt variable is the alternative image text that assumes null as default, or a string.

The function phutil_nonempty_string() will report alien types, and this is OK here.

src/applications/files/document/render/PhabricatorDocumentRenderingEngine.php
63

✅ I verified the above line

The Aphront#getStr() only returns strings, or null (default).

The function phutil_nonempty_string() will report other alien types, and that is OK.

68

✅ I verified the above line

The Aphront#getStr() only returns strings, or null (default).

The function phutil_nonempty_string() will report other alien types, and that is OK.

src/applications/files/storage/PhabricatorFile.php
1281

✅ I verified the above line

The $alt variable is the alternative image text that assumes null as default, or a string.

The function phutil_nonempty_string() will report alien types, and this is good.

This revision is now accepted and ready to land.May 5 2023, 20:34