Page MenuHomePhabricator

HHVM 3.19 incompability: TypeError: Argument 1 passed to mysql_real_escape_string() must be an instance of string, int given
Closed, ResolvedPublic

Description

After upgrading HHVM from 3.18.2 to 3.19.1, MW 1.28.1 update script (I did git pull and composer update) fails with the following error:

Fatal error: Uncaught TypeError: Argument 1 passed to mysql_real_escape_string() must be an instance of string, int given in /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqli.php:314
Stack trace:
#0 (): mysql_real_escape_string()
#1 /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqli.php(314): mysqli->real_escape_string()
#2 /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqlBase.php(602): DatabaseMysqli->mysqlRealEscapeString()
#3 /var/www/wiki/w/includes/libs/rdbms/database/Database.php(1985): DatabaseMysqlBase->strencode()
#4 /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqlBase.php(618): Database->addQuotes()
#5 /var/www/wiki/w/includes/libs/rdbms/database/Database.php(1621): DatabaseMysqlBase->addQuotes()
#6 /var/www/wiki/w/includes/libs/rdbms/database/Database.php(2159): Database->makeList()
#7 /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqlBase.php(486): Database->nativeReplace()
#8 /var/www/wiki/w/extensions/SemanticMediaWiki/src/SQLStore/TableIntegrityExaminer.php(154): DatabaseMysqlBase->replace()
#9 /var/www/wiki/w/extensions/SemanticMediaWiki/src/SQLStore/TableIntegrityExaminer.php(84): SMW\SQLStore\TableIntegrityExaminer->doCheckPredefinedPropertyIndices()
#10 /var/www/wiki/w/extensions/SemanticMediaWiki/src/SQLStore/Installer.php(115): SMW\SQLStore\TableIntegrityExaminer->checkOnPostCreation()
#11 /var/www/wiki/w/extensions/SemanticMediaWiki/includes/storage/SQLStore/SMW_SQLStore3.php(376): SMW\SQLStore\Installer->install()
#12 /var/www/wiki/w/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php(439): SMWSQLStore3->setup()
#13 /var/www/wiki/w/includes/installer/DatabaseUpdater.php(472): SMW\Store::setupStore()
#14 /var/www/wiki/w/includes/installer/DatabaseUpdater.php(437): DatabaseUpdater->runUpdates()
#15 /var/www/wiki/w/maintenance/update.php(172): DatabaseUpdater->doUpdates()
#16 /var/www/wiki/w/maintenance/doMaintenance.php(111): UpdateMediaWiki->execute()
#17 /var/www/wiki/w/maintenance/update.php(217): include()
#18 {main}
[2314eb5536b4b8f0d66f4bd6] [no req]   __SystemLib\TypeError from line 314 of /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqli.php: Argument 1 passed to mysql_real_escape_string() must be an instance of string, int given
Backtrace:
#0 [internal function]: mysql_real_escape_string(integer, resource)
#1 /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqli.php(314): mysqli->real_escape_string(integer)
#2 /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqlBase.php(602): DatabaseMysqli->mysqlRealEscapeString(integer)
#3 /var/www/wiki/w/includes/libs/rdbms/database/Database.php(1985): DatabaseMysqlBase->strencode(integer)
#4 /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqlBase.php(618): Database->addQuotes(integer)
#5 /var/www/wiki/w/includes/libs/rdbms/database/Database.php(1621): DatabaseMysqlBase->addQuotes(integer)
#6 /var/www/wiki/w/includes/libs/rdbms/database/Database.php(2159): Database->makeList(array)
#7 /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqlBase.php(486): Database->nativeReplace(string, array, string)
#8 /var/www/wiki/w/extensions/SemanticMediaWiki/src/SQLStore/TableIntegrityExaminer.php(154): DatabaseMysqlBase->replace(string, array, array, string)
#9 /var/www/wiki/w/extensions/SemanticMediaWiki/src/SQLStore/TableIntegrityExaminer.php(84): SMW\SQLStore\TableIntegrityExaminer->doCheckPredefinedPropertyIndices(DatabaseMysqli)
#10 /var/www/wiki/w/extensions/SemanticMediaWiki/src/SQLStore/Installer.php(115): SMW\SQLStore\TableIntegrityExaminer->checkOnPostCreation(SMW\SQLStore\TableBuilder\MySQLTableBuilder)
#11 /var/www/wiki/w/extensions/SemanticMediaWiki/includes/storage/SQLStore/SMW_SQLStore3.php(376): SMW\SQLStore\Installer->install(MysqlUpdater)
#12 /var/www/wiki/w/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php(439): SMWSQLStore3->setup(MysqlUpdater)
#13 /var/www/wiki/w/includes/installer/DatabaseUpdater.php(472): SMW\Store::setupStore(MysqlUpdater, array)
#14 /var/www/wiki/w/includes/installer/DatabaseUpdater.php(437): DatabaseUpdater->runUpdates(array, boolean)
#15 /var/www/wiki/w/maintenance/update.php(172): DatabaseUpdater->doUpdates(array)
#16 /var/www/wiki/w/maintenance/doMaintenance.php(111): UpdateMediaWiki->execute()
#17 /var/www/wiki/w/maintenance/update.php(217): include(string)
#18 {main}

The same error with mysql_real_escape_string() happened before the update script when I simply tried to access the wiki with the following in /var/log/hhvm/error.log:

Fatal error: Uncaught TypeError: Argument 1 passed to mysql_real_escape_string() must be an instance of string, int given in /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqli.php:314
Stack trace:
#0 (): mysql_real_escape_string()\n#1 /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqli.php(314): mysqli->real_escape_string()
#2 /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqlBase.php(602): DatabaseMysqli->mysqlRealEscapeString()
#3 /var/www/wiki/w/includes/libs/rdbms/database/Database.php(1971): DatabaseMysqlBase->strencode()
#4 /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqlBase.php(618): Database->addQuotes()
$5 /var/www/wiki/w/includes/libs/rdbms/database/Database.php(1618): DatabaseMysqlBase->addQuotes()
#6 /var/www/wiki/w/includes/libs/rdbms/database/Database.php(1296): Database->makeList()
#7 /var/www/wiki/w/includes/libs/rdbms/database/Database.php(1252): Database->selectSQLText()
#8 /var/www/wiki/w/includes/cache/MessageCache.php(480): Database->select()
#9 /var/www/wiki/w/includes/cache/MessageCache.php(403): MessageCache->loadFromDB()
#10 /var/www/wiki/w/includes/cache/MessageCache.php(325): MessageCache->loadFromDBWithLock()
#11 /var/www/wiki/w/includes/cache/MessageCache.php(927): MessageCache->load()
#12 /var/www/wiki/w/includes/cache/MessageCache.php(858): MessageCache->getMsgFromNamespace()
#13 /var/www/wiki/w/includes/cache/MessageCache.php(826): MessageCache->getMessageForLang()
#14 /var/www/wiki/w/includes/cache/MessageCache.php(767): MessageCache->getMessageFromFallbackChain()
#15 /var/www/wiki/w/includes/Message.php(1188): MessageCache->get()
#16 /var/www/wiki/w/includes/Message.php(950): Message->fetchMessage()
#17 /var/www/wiki/w/extensions/Gadgets/includes/MediaWikiGadgetsDefinitionRepo.php(113): Message->exists()
#18 /var/www/wiki/w/extensions/Gadgets/includes/MediaWikiGadgetsDefinitionRepo.php(83): MediaWikiGadgetsDefinitionRepo->fetchStructuredList()
#19 /var/www/wiki/w/includes/libs/objectcache/WANObjectCache.php(1004): Closure$MediaWikiGadgetsDefinitionRepo::loadGadgets()
#20 /var/www/wiki/w/includes/libs/objectcache/WANObjectCache.php(906): WANObjectCache->doGetWithSetCallback()
#21 /var/www/wiki/w/extensions/Gadgets/includes/MediaWikiGadgetsDefinitionRepo.php(91): WANObjectCache->getWithSetCallback()
#22 /var/www/wiki/w/extensions/Gadgets/includes/MediaWikiGadgetsDefinitionRepo.php(23): MediaWikiGadgetsDefinitionRepo->loadGadgets()
#23 /var/www/wiki/w/extensions/Gadgets/includes/GadgetRepo.php(36): MediaWikiGadgetsDefinitionRepo->getGadgetIds()
#24 /var/www/wiki/w/extensions/Gadgets/GadgetHooks.php(52): GadgetRepo->getStructuredList()
#25 /var/www/wiki/w/includes/Hooks.php(195): GadgetHooks::userGetDefaultOptions()
#26 /var/www/wiki/w/includes/user/User.php(1552): Hooks::run()
#27 /var/www/wiki/w/includes/user/User.php(5131): User::getDefaultOptions()
#28 /var/www/wiki/w/includes/user/User.php(2768): User->loadOptions()
#29 /var/www/wiki/w/includes/context/RequestContext.php(423): User->getOption()
#30 /var/www/wiki/w/includes/context/ContextSource.php(153): RequestContext->getSkin()
#31 /var/www/wiki/w/extensions/MobileFrontend/includes/MobileFrontend.hooks.php(587): ContextSource->getSkin()
#32 /var/www/wiki/w/includes/Hooks.php(195): MobileFrontendHooks::onSpecialPageBeforeExecute()
#33 /var/www/wiki/w/includes/specialpage/SpecialPage.php(515): Hooks::run()
#34 /var/www/wiki/w/includes/specialpage/SpecialPageFactory.php(576): SpecialPage->run()
#35 /var/www/wiki/w/includes/MediaWiki.php(283): SpecialPageFactory::executePath()
#36 /var/www/wiki/w/includes/MediaWiki.php(851): MediaWiki->performRequest()
#37 /var/www/wiki/w/includes/MediaWiki.php(512): MediaWiki->main()
#38 /var/www/wiki/w/index.php(43): MediaWiki->run()
#39 {main}
Exception handler threw an object exception: TypeError: Argument 1 passed to mysql_real_escape_string() must be an instance of string, int given in /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqli.php:314
Stack trace:
#0 (): mysql_real_escape_string()
#1 /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqli.php(314): mysqli->real_escape_string()
#2 /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqlBase.php(602): DatabaseMysqli->mysqlRealEscapeString()
#3 /var/www/wiki/w/includes/libs/rdbms/database/Database.php(1971): DatabaseMysqlBase->strencode()
#4 /var/www/wiki/w/includes/libs/rdbms/database/DatabaseMysqlBase.php(618): Database->addQuotes()
#5 /var/www/wiki/w/includes/libs/rdbms/database/Database.php(1618): DatabaseMysqlBase->addQuotes()
#6 /var/www/wiki/w/includes/libs/rdbms/database/Database.php(1296): Database->makeList()
#7 /var/www/wiki/w/includes/libs/rdbms/database/Database.php(1252): Database->selectSQLText()
#8 /var/www/wiki/w/includes/cache/MessageCache.php(480): Database->select()
#9 /var/www/wiki/w/includes/cache/MessageCache.php(403): MessageCache->loadFromDB()
#10 /var/www/wiki/w/includes/cache/MessageCache.php(325): MessageCache->loadFromDBWithLock()
#11 /var/www/wiki/w/includes/cache/MessageCache.php(927): MessageCache->load()
#12 /var/www/wiki/w/includes/cache/MessageCache.php(858): MessageCache->getMsgFromNamespace()
#13 /var/www/wiki/w/includes/cache/MessageCache.php(826): MessageCache->getMessageForLang()
#14 /var/www/wiki/w/includes/cache/MessageCache.php(767): MessageCache->getMessageFromFallbackChain()
#15 /var/www/wiki/w/includes/Message.php(1188): MessageCache->get()
#16 /var/www/wiki/w/includes/Message.php(802): Message->fetchMessage()
#17 /var/www/wiki/w/includes/Message.php(902): Message->toString()
#18 /var/www/wiki/w/includes/exception/MWExceptionRenderer.php(246): Message->text()
#19 /var/www/wiki/w/includes/exception/MWExceptionRenderer.php(164): MWExceptionRenderer::msg()
#20 /var/www/wiki/w/includes/exception/MWExceptionRenderer.php(50): MWExceptionRenderer::reportHTML()
#21 /var/www/wiki/w/includes/exception/MWExceptionHandler.php(71): MWExceptionRenderer::output()
#22 /var/www/wiki/w/includes/exception/MWExceptionHandler.php(137): MWExceptionHandler::report()
#23 (): MWExceptionHandler::handleException()
#24 {main}

BTW, why is a deprecated function used at all?

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptApr 23 2017, 6:37 PM
alex-mashin updated the task description. (Show Details)Apr 23 2017, 6:46 PM
Aklapper renamed this task from HHVM 3.19 incompability in database driver to HHVM 3.19 incompability: TypeError: Argument 1 passed to mysql_real_escape_string() must be an instance of string, int given.Apr 24 2017, 9:56 AM
alex-mashin updated the task description. (Show Details)Apr 29 2017, 2:56 AM

I worked around this bug with the following change to (path to mediawiki)/includes/libs/rdbms/database/DatabaseMysqli.php:
in line 314 within protected function mysqlRealEscapeString( $s ) replace:
return $conn->real_escape_string( $s );
with:
return $conn->real_escape_string( (string) $s );.

BTW, why is a deprecated function used at all?

Which deprecated function?

alex-mashin added a comment.EditedMay 24 2017, 11:49 AM

BTW, why is a deprecated function used at all?

Which deprecated function?

Forget it, I wrote the comment before reading the code, thinking that mysql_real_escape_string () is a standard PHP function, not a method.

BTW, why is a deprecated function used at all?

Which deprecated function?

Forget it, I wrote the comment before reading the code, thinking that mysql_real_escape_string () is a standard PHP function, not a method.

Yeah, it's using http://php.net/manual/en/mysqli.real-escape-string.php (see stacktrace). It is confusing, though, that the message wrongly refers to it as if it was a method of the deprecated mysql library, instead of mysqli.

Change 381617 had a related patch set uploaded (by Gerrit Patch Uploader; owner: Alexander I. Mashin):
[mediawiki/core@master] T163646 HHVM 3.19 incompability: TypeError: Argument 1 passed to mysql_real_escape_string() must be an instance of string, int given

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

Change 381617 had a related patch set uploaded (by Legoktm; owner: Alexander I. Mashin):
[mediawiki/core@master] Ensure only strings are passed to mysql_real_escape_string()

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

Krinkle removed a subscriber: Krinkle.Oct 3 2017, 6:03 PM

Change 381617 merged by jenkins-bot:
[mediawiki/core@master] Ensure only strings are passed to mysql_real_escape_string()

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

Change 384550 had a related patch set uploaded (by Krinkle; owner: Alexander I. Mashin):
[mediawiki/core@REL1_30] Ensure only strings are passed to mysql_real_escape_string()

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

Change 384551 had a related patch set uploaded (by Krinkle; owner: Alexander I. Mashin):
[mediawiki/core@REL1_29] Ensure only strings are passed to mysql_real_escape_string()

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

Krinkle closed this task as Resolved.
Krinkle claimed this task.

Backported to 1.30 and 1.29. Originally reported for 1.28 but thats almost out of support and the patch doesn't apply cleanly there. It isn't known to affect 1.27 (LTS).

https://www.mediawiki.org/wiki/Version_lifecycle

Change 384550 merged by jenkins-bot:
[mediawiki/core@REL1_30] Ensure only strings are passed to mysql_real_escape_string()

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

Change 384551 merged by jenkins-bot:
[mediawiki/core@REL1_29] Ensure only strings are passed to mysql_real_escape_string()

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