Page MenuHomePhabricator

PHP Notice: Uninitialized string offset: 0
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error
normalized_message
[{reqId}] {exception_url}   PHP Notice: Uninitialized string offset: 0
exception.trace
from /srv/mediawiki/php-1.38.0-wmf.20/includes/cache/MessageCache.php(139)
#0 /srv/mediawiki/php-1.38.0-wmf.20/includes/cache/MessageCache.php(139): MWExceptionHandler::handleError(integer, string, string, integer, array)
#1 /srv/mediawiki/php-1.38.0-wmf.20/includes/api/ApiQueryAllMessages.php(182): MessageCache::normalizeKey(string)
#2 /srv/mediawiki/php-1.38.0-wmf.20/includes/api/ApiQuery.php(629): ApiQueryAllMessages->execute()
#3 /srv/mediawiki/php-1.38.0-wmf.20/includes/api/ApiMain.php(1890): ApiQuery->execute()
#4 /srv/mediawiki/php-1.38.0-wmf.20/includes/api/ApiMain.php(868): ApiMain->executeAction()
#5 /srv/mediawiki/php-1.38.0-wmf.20/includes/api/ApiMain.php(839): ApiMain->executeActionWithErrorHandling()
#6 /srv/mediawiki/php-1.38.0-wmf.20/api.php(90): ApiMain->execute()
#7 /srv/mediawiki/php-1.38.0-wmf.20/api.php(45): wfApiMain()
#8 /srv/mediawiki/w/api.php(3): require(string)
#9 {main}

And this associated one

normalized_message
[{reqId}] {exception_url}   PHP Warning: Cannot assign an empty string to a string offset
exception.trace
from /srv/mediawiki/php-1.38.0-wmf.20/includes/cache/MessageCache.php(139)
#0 /srv/mediawiki/php-1.38.0-wmf.20/includes/cache/MessageCache.php(139): MWExceptionHandler::handleError(integer, string, string, integer, array)
#1 /srv/mediawiki/php-1.38.0-wmf.20/includes/api/ApiQueryAllMessages.php(182): MessageCache::normalizeKey(string)
#2 /srv/mediawiki/php-1.38.0-wmf.20/includes/api/ApiQuery.php(629): ApiQueryAllMessages->execute()
#3 /srv/mediawiki/php-1.38.0-wmf.20/includes/api/ApiMain.php(1890): ApiQuery->execute()
#4 /srv/mediawiki/php-1.38.0-wmf.20/includes/api/ApiMain.php(868): ApiMain->executeAction()
#5 /srv/mediawiki/php-1.38.0-wmf.20/includes/api/ApiMain.php(839): ApiMain->executeActionWithErrorHandling()
#6 /srv/mediawiki/php-1.38.0-wmf.20/api.php(90): ApiMain->execute()
#7 /srv/mediawiki/php-1.38.0-wmf.20/api.php(45): wfApiMain()
#8 /srv/mediawiki/w/api.php(3): require(string)
#9 {main}
Notes

A small burst of these appeared in logs. I haven't seen this before.

Details

MediaWiki Version
1.38.0-wmf.20
Request URL
https://ar.wiktionary.org/w/api.php?action=query&meta=*&ammessages=*&amlang=*&amnocontent=*

Event Timeline

Krinkle subscribed.

MessageCache::normalizeKey applies a strtolower operation to the first character of its string parameter, which emits this error when given an empty string.

MessageCache itself avoids this by not calling it with empty strings. ApiQueryAllMessages calls this seemingly-internal method directly on user input, hence fails.

While the empty string cannot exist as a message, it is considered a valid interface message key by all localisation-related classes that I checked, it simply results in boolean false the same as for other message keys that don't exist. The Action API allows empty string in its multi-value parameters, and omitting it from the result would create a confusing situation.

Hence, I think the call from ApiQueryAllMessages is actually reasonable, so maybe normalizeKey should be fixed instead?

Change 759641 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/core@master] MessageCache: Avoid Undefined offset in normalizeKey()

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

Krinkle added a project: Performance-Team.

Change 759641 merged by jenkins-bot:

[mediawiki/core@master] MessageCache: Avoid Undefined offset in normalizeKey()

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