Page MenuHomePhabricator

PHP Warning: implode(): Invalid arguments passed
Closed, ResolvedPublicBUG REPORT

Description

What is the problem?

With this clienthints payload:

{"bitness": null, "platformVersion": 29280, "brands": {"-70": "n", "null": -19480, "false": "\\u00887\\u0007", "\\u0016\\ud95c\\udda46BX": true, "m": ""}, "platform": "", "architecture": null, "mobile": "r", "model": false}

I see this error in the logs:

[error] [139f0c093f36788576efeabe] /bare/rest.php/checkuser/v0/useragent-clienthints/revision/16882   PHP Warning: implode(): Invalid arguments passed
#0 [internal function]: MWExceptionHandler::handleError()
#1 /home/drw/wikimedia/srv/bare/extensions/CheckUser/src/ClientHints/ClientHintsData.php(128): implode()
#2 /home/drw/wikimedia/srv/bare/extensions/CheckUser/src/Services/UserAgentClientHintsManager.php(151): MediaWiki\CheckUser\ClientHints\ClientHintsData->toDatabaseRows()
#3 /home/drw/wikimedia/srv/bare/extensions/CheckUser/src/Services/UserAgentClientHintsManager.php(114): MediaWiki\CheckUser\Services\UserAgentClientHintsManager->insertMappingRows()
#4 /home/drw/wikimedia/srv/bare/extensions/CheckUser/src/Api/Rest/Handler/UserAgentClientHintsHandler.php(113): MediaWiki\CheckUser\Services\UserAgentClientHintsManager->insertClientHintValues()
#5 /home/drw/wikimedia/srv/bare/includes/Rest/SimpleHandler.php(38): MediaWiki\CheckUser\Api\Rest\Handler\UserAgentClientHintsHandler->run()
#6 /home/drw/wikimedia/srv/bare/includes/Rest/Router.php(517): MediaWiki\Rest\SimpleHandler->execute()
#7 /home/drw/wikimedia/srv/bare/includes/Rest/Router.php(422): MediaWiki\Rest\Router->executeHandler()
#8 /home/drw/wikimedia/srv/bare/includes/Rest/EntryPoint.php(195): MediaWiki\Rest\Router->execute()
#9 /home/drw/wikimedia/srv/bare/includes/Rest/EntryPoint.php(135): MediaWiki\Rest\EntryPoint->execute()
#10 /home/drw/wikimedia/srv/bare/rest.php(31): MediaWiki\Rest\EntryPoint::main()
#11 {main}

The client sees a success message. The warning is only in the logs.

It does not seem to prevent other client hints data being recorded.

Steps to reproduce problem
  1. Setup debug logging on your local wiki (https://www.mediawiki.org/wiki/Manual:How_to_debug#Setting_up_a_debug_log_file)
  2. Install checkuser
  3. While logged out, make an edit on Firefox
  4. Find the revision ID of the edit you just made
  5. Run this command, replace <rev id> with the revision ID you just found:
curl 'http://localhost/bare/rest.php/checkuser/v0/useragent-clienthints/revision/<rev id>' -H 'Content-Type: application/json'   --data-raw '{"bitness": null, "platformVersion": 29280, "brands": {"-70": "n", "null": -19480, "false": "\\u00887\\u0007", "\\u0016\\ud95c\\udda46BX": true, "m": ""}, "platform": "", "architecture": null, "mobile": "r", "model": false}'
  1. Inspect your debug.log file

Expected behavior: No errors, exceptions or warnings.
Observed behavior: You will see several lines with PHP Warning: implode(): Invalid arguments passed.

Environment

Wiki(s): MediaWiki 1.41.0-alpha (80d62c5) 10:11, 25 August 2023. CheckUser 2.5 (f1ead0e) 10:13, 25 August 2023.

QA Results - Local, VS

Event Timeline

Change 952485 had a related patch set uploaded (by Dreamy Jazz; author: Dreamy Jazz):

[mediawiki/extensions/CheckUser@master] clienthints: Only call implode when the item is an array

https://gerrit.wikimedia.org/r/952485

It seems in my PHP version, the implode method requires that the arrray argument actually be an array (instead of warning). When testing the patch I've made fixed this issue and I couldn't get a warning and/or error to occur when using the payload detailed in the task description.

It seems in my PHP version, the implode method requires that the arrray argument actually be an array (instead of warning). When testing the patch I've made fixed this issue and I couldn't get a warning and/or error to occur when using the payload detailed in the task description.

PHP 8.0+?

It seems in my PHP version, the implode method requires that the arrray argument actually be an array (instead of warning). When testing the patch I've made fixed this issue and I couldn't get a warning and/or error to occur when using the payload detailed in the task description.

PHP 8.0+?

Yes. I run an instance in docker, which uses 8.1.

However, I don't think I need to test on a lower version of PHP as the method I wrote explicitly checks if it is an array therefore avoiding the problem.

https://www.php.net/manual/en/function.implode.php

With them dropping support for implode(string $separator, array $array) in PHP 8.0+, I'm guessing it introduced harder type checks etc

Change 952485 merged by jenkins-bot:

[mediawiki/extensions/CheckUser@master] clienthints: Only call implode when the item is an array

https://gerrit.wikimedia.org/r/952485

GMikesell-WMF subscribed.

@Dreamy_Jazz I did not come across any errors or warnings in the debug.log. The task will be moved to Done. Thanks for all your work!

Status: ✅ PASS
Environment: Wiki(s): MediaWiki 1.41.0-alpha (bc735a5) 114:54, 30 August 2023. CheckUser 2.5 (9ed2b65) 18:12, 29 August 2023
OS: macOS Ventura
Browser: Chrome 116
Device: MBP
Emulated Device:: N/A
Test Links: : VS

✅AC1: https://phabricator.wikimedia.org/T344993

2023-08-30_08-41-44.png (1×1 px, 469 KB)