Page MenuHomePhabricator

Some parsercache keys yield error when tried to save into memcache
Closed, DuplicatePublic

Description

Noticed this while looking at 500s, it looks like some urls with uselang= and utf8 characters don't mix well. AFAICT this is traffic from crawlers since the selection is literally "<lang>" but with unicode angled brackets. E.g. exception id WT5UdgpAADwAAIKy1jAAAABE. It does look like a mismatch in what's allowed in mysql and memcache

/srv/mediawiki/php-1.30.0-wmf.4/includes/libs/objectcache/MemcachedBagOStuff.php:156
Key contains invalid characters: commonswiki:pcache:idhash:3351971-0!userlang=⧼lang⧽
#0 /srv/mediawiki/php-1.30.0-wmf.4/includes/libs/objectcache/MemcachedPeclBagOStuff.php(145): MemcachedBagOStuff->validateKeyEncoding(string)
#1 /srv/mediawiki/php-1.30.0-wmf.4/includes/libs/objectcache/MemcachedBagOStuff.php(56): MemcachedPeclBagOStuff->getWithToken(string, NULL, integer)
#2 /srv/mediawiki/php-1.30.0-wmf.4/includes/libs/objectcache/BagOStuff.php(185): MemcachedBagOStuff->doGet(string, integer)
#3 /srv/mediawiki/php-1.30.0-wmf.4/includes/libs/objectcache/MultiWriteBagOStuff.php(112): BagOStuff->get(string, integer)
#4 /srv/mediawiki/php-1.30.0-wmf.4/includes/libs/objectcache/BagOStuff.php(185): MultiWriteBagOStuff->doGet(string, integer)
#5 /srv/mediawiki/php-1.30.0-wmf.4/includes/parser/ParserCache.php(230): BagOStuff->get(string, integer, integer)
#6 /srv/mediawiki/php-1.30.0-wmf.4/includes/page/Article.php(528): ParserCache->get(WikiFilePage, ParserOptions)
#7 /srv/mediawiki/php-1.30.0-wmf.4/includes/page/ImagePage.php(162): Article->view()
#8 /srv/mediawiki/php-1.30.0-wmf.4/includes/actions/ViewAction.php(68): ImagePage->view()
#9 /srv/mediawiki/php-1.30.0-wmf.4/includes/MediaWiki.php(499): ViewAction->show()
#10 /srv/mediawiki/php-1.30.0-wmf.4/includes/MediaWiki.php(293): MediaWiki->performAction(ImagePage, Title)
#11 /srv/mediawiki/php-1.30.0-wmf.4/includes/MediaWiki.php(862): MediaWiki->performRequest()
#12 /srv/mediawiki/php-1.30.0-wmf.4/includes/MediaWiki.php(523): MediaWiki->main()
#13 /srv/mediawiki/php-1.30.0-wmf.4/index.php(43): MediaWiki->run()
#14 /srv/mediawiki/w/index.php(3): include(string)
#15 {main}
[WT5UdgpAADwAAIKy1jAAAABE] /wiki/File:Edit_4x_rifle_scope.jpg?uselang=%E2%A7%BCLang%E2%A7%BD   Exception from line 156 of /srv/mediawiki/php-1.30.0-wmf.4/includes/libs/objectcache/MemcachedBagOStuff.php: Key contains invalid characters: commonswiki:pcache:idhash:3351971-0!userlang=⧼lang⧽

Event Timeline

elukey added a subscriber: elukey.Jun 12 2017, 9:48 AM
hashar added a subscriber: hashar.

MediaWiki has some sanity check for the keys:

includes/libs/objectcache/MemcachedBagOStuff.php
/**
 * Ensure that a key is safe to use (contains no control characters and no
 * characters above the ASCII range.)
 *
 * @param string $key
 * @return string
 * @throws Exception
 */
public function validateKeyEncoding( $key ) {
    if ( preg_match( '/[^\x21-\x7e]+/', $key ) ) {
        throw new Exception( "Key contains invalid characters: $key" );
    }
    return $key;
}

And surely a key with unicode angle brackets is wrong:

commonswiki:pcache:idhash:3351971-0!userlang=⧼lang⧽

MediaWiki core patch 0facbe3e3dfa4df81c01323b5f2aeacf880a1054 / https://gerrit.wikimedia.org/r/#/c/354504/ is in since 1.30.0-wmf.4 and might be related

MediaWiki core patch 0facbe3e3dfa4df81c01323b5f2aeacf880a1054 / https://gerrit.wikimedia.org/r/#/c/354504/ is in since 1.30.0-wmf.4 and might be related

Seems unlikely, that change doesn't affect the way userlang is used.