Page MenuHomePhabricator

PHP Warning: Invalid argument supplied for foreach() in Parser::finalizeHeadings()
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error
normalized_message
[{reqId}] {exception_url}   PHP Warning: Invalid argument supplied for foreach()
exception.trace
from /srv/mediawiki/php-1.43.0-wmf.4/includes/parser/Parser.php(4535)
#0 /srv/mediawiki/php-1.43.0-wmf.4/includes/parser/Parser.php(4535): MWExceptionHandler::handleError(integer, string, string, integer, array)
#1 /srv/mediawiki/php-1.43.0-wmf.4/includes/parser/Parser.php(1654): MediaWiki\Parser\Parser->finalizeHeadings(string, string, boolean)
#2 /srv/mediawiki/php-1.43.0-wmf.4/includes/parser/Parser.php(725): MediaWiki\Parser\Parser->internalParse(string)
#3 /srv/mediawiki/php-1.43.0-wmf.4/includes/content/WikitextContentHandler.php(376): MediaWiki\Parser\Parser->parse(string, MediaWiki\Title\Title, ParserOptions, boolean, boolean, integer)
#4 /srv/mediawiki/php-1.43.0-wmf.4/includes/content/ContentHandler.php(1674): WikitextContentHandler->fillParserOutput(WikitextContent, MediaWiki\Content\Renderer\ContentParseParams, MediaWiki\Parser\ParserOutput)
#5 /srv/mediawiki/php-1.43.0-wmf.4/includes/content/Renderer/ContentRenderer.php(67): ContentHandler->getParserOutput(WikitextContent, MediaWiki\Content\Renderer\ContentParseParams)
#6 /srv/mediawiki/php-1.43.0-wmf.4/includes/Revision/RenderedRevision.php(260): MediaWiki\Content\Renderer\ContentRenderer->getParserOutput(WikitextContent, MediaWiki\Title\Title, MediaWiki\Revision\RevisionStoreRecord, ParserOptions, boolean)
#7 /srv/mediawiki/php-1.43.0-wmf.4/includes/Revision/RenderedRevision.php(232): MediaWiki\Revision\RenderedRevision->getSlotParserOutputUncached(WikitextContent, boolean)
#8 /srv/mediawiki/php-1.43.0-wmf.4/includes/Revision/RevisionRenderer.php(226): MediaWiki\Revision\RenderedRevision->getSlotParserOutput(string, array)
#9 /srv/mediawiki/php-1.43.0-wmf.4/includes/Revision/RevisionRenderer.php(164): MediaWiki\Revision\RevisionRenderer->combineSlotOutput(MediaWiki\Revision\RenderedRevision, ParserOptions, array)
#10 [internal function]: MediaWiki\Revision\RevisionRenderer->MediaWiki\Revision\{closure}(MediaWiki\Revision\RenderedRevision, array)
#11 /srv/mediawiki/php-1.43.0-wmf.4/includes/Revision/RenderedRevision.php(199): call_user_func(Closure, MediaWiki\Revision\RenderedRevision, array)
#12 /srv/mediawiki/php-1.43.0-wmf.4/includes/poolcounter/PoolWorkArticleView.php(91): MediaWiki\Revision\RenderedRevision->getRevisionParserOutput()
#13 /srv/mediawiki/php-1.43.0-wmf.4/includes/poolcounter/PoolWorkArticleViewOld.php(70): MediaWiki\PoolCounter\PoolWorkArticleView->renderRevision()
#14 /srv/mediawiki/php-1.43.0-wmf.4/includes/poolcounter/PoolCounterWork.php(171): MediaWiki\PoolCounter\PoolWorkArticleViewOld->doWork()
#15 /srv/mediawiki/php-1.43.0-wmf.4/includes/page/ParserOutputAccess.php(355): MediaWiki\PoolCounter\PoolCounterWork->execute()
#16 /srv/mediawiki/php-1.43.0-wmf.4/includes/page/Article.php(761): MediaWiki\Page\ParserOutputAccess->getParserOutput(WikiPage, ParserOptions, MediaWiki\Revision\RevisionStoreRecord, integer)
#17 /srv/mediawiki/php-1.43.0-wmf.4/includes/page/Article.php(563): Article->generateContentOutput(MediaWiki\User\User, ParserOptions, integer, MediaWiki\Output\OutputPage, array)
#18 /srv/mediawiki/php-1.43.0-wmf.4/includes/actions/ViewAction.php(78): Article->view()
#19 /srv/mediawiki/php-1.43.0-wmf.4/includes/actions/ActionEntryPoint.php(731): ViewAction->show()
#20 /srv/mediawiki/php-1.43.0-wmf.4/includes/actions/ActionEntryPoint.php(508): MediaWiki\Actions\ActionEntryPoint->performAction(Article, MediaWiki\Title\Title)
#21 /srv/mediawiki/php-1.43.0-wmf.4/includes/actions/ActionEntryPoint.php(145): MediaWiki\Actions\ActionEntryPoint->performRequest()
#22 /srv/mediawiki/php-1.43.0-wmf.4/includes/MediaWikiEntryPoint.php(199): MediaWiki\Actions\ActionEntryPoint->execute()
#23 /srv/mediawiki/php-1.43.0-wmf.4/index.php(58): MediaWiki\MediaWikiEntryPoint->run()
#24 /srv/mediawiki/w/index.php(3): require(string)
#25 {main}
Impact

Unclear (only seen three times over the past seven days – all of them on the same request URL).

Notes

Details

Request URL
https://simple.wikipedia.org/w/index.php?oldid=4528223&title=Wikipedia:Sandbox

Event Timeline

The affected code is:

		# split up and insert constructed headlines
		$blocks = preg_split( '/<H[1-6].*?>[\s\S]*?<\/H[1-6]>/i', $text );
		$i = 0;

		// build an array of document sections
		$sections = [];
		foreach ( $blocks as $block ) {

Presumably, preg_split() returned false, but I don’t know why it would do that – the only documented error condition for this function is an invalid pattern, yet the pattern is constant and hasn’t been touched since 2015.

The affected revision appears to be vandalism from 2013 (I’ve redacted what looks like some person’s name) with lots of <h1> elements (ca. 2700 of them):

image.png (302×482 px, 45 KB)

Change #1053067 had a related patch set uploaded (by Umherirrender; author: Umherirrender):

[mediawiki/core@master] parser: Check for backtrack limit failure from preg_split

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

Change #1060831 had a related patch set uploaded (by Thiemo Kreuz (WMDE); author: Thiemo Kreuz (WMDE)):

[mediawiki/core@master] parser: Optimize heading regex for backtracking performance

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

Change #1053067 abandoned by Umherirrender:

[mediawiki/core@master] parser: Check for backtrack limit failure from preg_split

Reason:

regex change is suggested in Id5c02ebe4fc05b27d6f270805296c619b79ada49

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

Change #1060831 merged by jenkins-bot:

[mediawiki/core@master] parser: Optimize heading regex for backtracking performance

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

Umherirrender reassigned this task from Umherirrender to thiemowmde.
Umherirrender subscribed.

The page provided as failure no longer shows an error and is visible.