[3.0] End the search for an avatar at the last resort - #9587
Open
albertlast wants to merge 1 commit into
Open
Conversation
The Avatar constructor tries each way of finding an image in turn, inside a loop that runs until it holds a URL that Url::isValid() accepts. The last of those ways is a 1x1 transparent GIF as a data URI, which is there so that there is always an answer. A data URI is not a URL that filter_var() will validate, so that answer never satisfied the condition, and the loop went round again, and again, until the request was killed. Reaching the last resort takes nothing exotic. The step before it only produces a URL when avatar_url is set, so a forum where that setting was never written hangs a PHP worker on every member who has an avatar. Leaving the loop rather than the switch is the whole change: at that point there is nothing further to try, which is what the case is for. Signed-off-by: albertlast <mathiaspapealbert@hotmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This change was produced by an LLM. The fix, the test, the commit message and
this description were all written by Claude (Anthropic), driven by @albertlast. It
has not yet had human code review.
Description
Avatar::__construct()looks for the member's image by trying each possibility inturn, inside
while (!$url->isValid()). The last possibility, reached when nothingelse produced anything, is a 1×1 transparent GIF as a data URI — there so that there
is always an answer:
Url::isValid()isfilter_var($url, FILTER_VALIDATE_URL), which rejects a dataURI. So that answer never satisfies the condition the loop is testing, the
switchfalls to
defaultagain on the next turn, and the loop never ends. The constructordoes not return, and the PHP worker running it spins until something kills it.
Reaching the last resort takes nothing exotic. The step before it is:
so a forum where
avatar_urlwas never written — or one whoseavatars/default.pngis not there — hangs on any member who has an avatar at all. Every page that shows
that member takes a worker with it.
The change is
break 2in place ofbreak: at that point there is nothing furtherto try, which is what the case is for.
Reproducing it
Without a forum, on
release-3.0as it stands:tests/Unit/AvatarFallbackTest.phpis that, as a test. Against the unfixedconstructor it does not fail so much as never finish —
phpunit --filter AvatarFallbackTesthad to be killed at 40 seconds, having printed nothing past itsheader. With the fix, both tests pass and the whole suite is back under a second.
The second test is the control: given an
avatar_url, the same avatar is found theordinary way and the loop ends where it always did.
Notes for review
id_memberis passed to the constructor because that is the one argument thatkeeps it away from the
attachmentstable, which is what makes this reachable fromthe unit suite at all.
AvatarTest.php, because [3.0][Testing] Cover four more merged fixes in the unit suite #9586 and[3.0] Look for a gallery avatar where the gallery is #9588 each add an Avatar test file of their own and I would rather they merge in
any order than have three PRs conflict on one file.
Issues References (Fixes|Related|Closes)
Related to #9586, #9588.