Page MenuHomePhabricator

Fatal error on Special:Translate for certain 'language' values
Closed, ResolvedPublicBug

Description

Error

Request ID: W6JmOArAMGAAAKt6@Y0AAABS

message
[{exception_id}] {exception_url}   MWException from line 229 of /srv/mediawiki/php-1.32.0-wmf.22/languages/Language.php: Invalid language code "###"
stacktrace
#0 /srv/mediawiki/php-1.32.0-wmf.22/languages/Language.php(210): Language::newFromCode(string)
#1 /srv/mediawiki/php-1.32.0-wmf.22/extensions/Translate/utils/TuxMessageTable.php(19): Language::factory(string)
#2 /srv/mediawiki/php-1.32.0-wmf.22/extensions/Translate/specials/SpecialTranslate.php(74): TuxMessageTable->fullTable()
#3 /srv/mediawiki/php-1.32.0-wmf.22/includes/specialpage/SpecialPage.php(569): SpecialTranslate->execute(NULL)
#4 /srv/mediawiki/php-1.32.0-wmf.22/includes/specialpage/SpecialPageFactory.php(581): SpecialPage->run(NULL)
#5 /srv/mediawiki/php-1.32.0-wmf.22/includes/MediaWiki.php(288): MediaWiki\Special\SpecialPageFactory->executePath(Title, RequestContext)
#6 /srv/mediawiki/php-1.32.0-wmf.22/includes/MediaWiki.php(868): MediaWiki->performRequest()
#7 /srv/mediawiki/php-1.32.0-wmf.22/includes/MediaWiki.php(525): MediaWiki->main()
#8 /srv/mediawiki/php-1.32.0-wmf.22/index.php(42): MediaWiki->run()
#9 /srv/mediawiki/w/index.php(3): include(string)

Notes

Reproducible at:

  • https://www.mediawiki.org/w/index.php?title=Special:Translate&group=page-Download&language=en'A=0&action=page&filter=
  • https://commons.wikimedia.org/w/index.php?title=Special:Translate&group=page-Download&language=en'A=0&action=page&filter=
  • https://meta.wikimedia.org/w/index.php?title=Special:Translate&group=page-Download&language=en'A=0&action=page&filter=

This has been in the logs for a while and did not yet have a task associated with it.

See also: T198054

Event Timeline

Krinkle created this task.Sep 19 2018, 3:32 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptSep 19 2018, 3:32 PM
Krinkle updated the task description. (Show Details)Sep 19 2018, 3:33 PM
Nemo_bis triaged this task as Normal priority.Dec 16 2018, 12:30 AM
abi_ claimed this task.Mar 3 2019, 7:24 AM
abi_ moved this task from Backlog to In Progress on the User-abi_ board.
abi_ moved this task from In Progress to Under Review on the User-abi_ board.

Was able to reproduce this issue in Local. As you can probably tell, the language code in the URL is invalid.

There are a couple of things to do here,

  1. When an invalid language code is encountered, fallback to user's language code.
  2. Check if Translate this page link can be generated incorrectly.

The patch submitted handles the first item in the list. Added a check to validate the language code, and if it is not valid the page will fallback to the user's language code.

In addition, as mentioned in the patch - https://gerrit.wikimedia.org/r/#/c/mediawiki/core/+/486327/, also added exception handling around the Language::factory call in TuxMessageTable class.

For the second item, I'm not sure how the user came across that language code. The language code is almost always set via the IContextSource, and the RequestContext already validates the language code before setting the value in setLanguage.

It might help to know,

  1. What was the page that the user was viewing before this happened? Would it be possible to get this via the access log?
  2. How often does this appear in the logs?

If the answer to #2 is rarely, I think it might be safe to assume that these are probably caused due to a typo.

Test Cases


TC #1 - Fallback to default language for invalid language code.

  1. Create a page and mark it for translation.
  2. Copy the translate this page link.
  3. Change the language query string value to en'A.
  4. Open the page.

Expected behavior: You should notice that the SpecialTranslate page opens with your preferred language selected in the ULS.

Patch for review: https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/Translate/+/494031/

(Not sure why the Gerrit bot is not linking the patches, will check this)

Change 494031 had a related patch set uploaded (by Abijeet Patro; owner: Abijeet Patro):
[mediawiki/extensions/Translate@master] Fix crash due to invalid language code passed to SpecialTranslate

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

Nikerabbit changed the subtype of this task from "Task" to "Bug Report".Mar 4 2019, 6:39 AM
abi_ moved this task from Under Review to In Progress on the User-abi_ board.Mar 4 2019, 7:15 PM
abi_ added a comment.Mar 4 2019, 7:17 PM

In addition, as mentioned in the patch - https://gerrit.wikimedia.org/r/#/c/mediawiki/core/+/486327/, also added exception handling around the Language::factory call in TuxMessageTable class.

Had a discussion with Niklas, and decided to validate the target language in TuxMessageTable class constructor and fall back to the user's preferred language if target language is invalid. Updated the patch accordingly.

abi_ moved this task from In Progress to Under Review on the User-abi_ board.Mar 5 2019, 3:06 AM

Change 494031 merged by jenkins-bot:
[mediawiki/extensions/Translate@master] Fix crash due to invalid language code passed to SpecialTranslate

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

abi_ moved this task from Under Review to QA on the User-abi_ board.Mar 5 2019, 9:21 AM
abi_ removed a project: Patch-For-Review.

Moved to QA.

Etonkovidova closed this task as Resolved.Mar 6 2019, 10:53 PM
Etonkovidova added a subscriber: Etonkovidova.

Checked on meta.wikimedia.beta.wmflabs.org.

Invalid lang codes fall back to English and the following page will be displayed to a user:

I've added the task to be checked after deployment.