Page MenuHomePhabricator

MimeAnalyzer throws `ValueError: Path cannot be empty` on PHP 8.0
Closed, ResolvedPublic

Description

Called from UploadBaseTest::testTitleValidation:

00:03:43.113 20) UploadBaseTest::testTitleValidation with data set #5 ('A', null, 8, 'upload title without extension')
00:03:43.113 ValueError: Path cannot be empty
00:03:43.113 
00:03:43.113 /workspace/src/includes/libs/mime/MimeAnalyzer.php:549
00:03:43.113 /workspace/src/includes/libs/mime/MimeAnalyzer.php:520
00:03:43.113 /workspace/src/includes/upload/UploadBase.php:1044
00:03:43.113 /workspace/src/tests/phpunit/includes/upload/UploadBaseTest.php:634
00:03:43.113 /workspace/src/tests/phpunit/includes/upload/UploadBaseTest.php:35
00:03:43.113 /workspace/src/tests/phpunit/MediaWikiIntegrationTestCase.php:446
00:03:43.113 /workspace/src/tests/phpunit/phpunit.php:75
00:03:43.113 /workspace/src/maintenance/doMaintenance.php:107
00:03:43.113 /workspace/src/tests/phpunit/phpunit.php:134
00:03:43.113 === Logs generated by test case
00:03:43.113 [objectcache] [debug] MainWANObjectCache using store {class} {"class":"EmptyBagOStuff"}
00:03:43.113 [localisation] [debug] LocalisationCache using store LCStoreNull []
00:03:43.113 [objectcache] [debug] MainWANObjectCache using store {class} {"class":"EmptyBagOStuff"}
00:03:43.113 [Mime] [info] MimeAnalyzer::guessMimeType: WARNING: use of the $ext parameter is deprecated. Use improveTypeFromExtension($mime, $ext) instead.
00:03:43.113  []
00:03:43.113 ===

Event Timeline

Said code is wrapped in Wikimedia\suppressWarnings(), but I suppose that's magically now insufficient?

Change 656979 had a related patch set uploaded (by Jforrester; owner: Jforrester):
[mediawiki/core@master] MimeAnalyzer: Exit early if provided path is empty/null

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

The warning being surpressed is from fopen for if the file doesn't exist or if we have no permission to read it. That still works in PHP 8.

The issue we are seeing here is that the path is an empty string, which was never valid and previously emitted a non-fatal error which became fatal in PHP 8.

It does indeed seem odd that the test is calling $magic->guessMimeType( $this->mTempPath ) where $this->mTempPath is null. That seems like a serious bug and probably means the class (or maybe just the test) isn't working correctly.

Krinkle assigned this task to Jdforrester-WMF.

Change 656979 merged by jenkins-bot:
[mediawiki/core@master] UploadBase: Don't call MimeAnalyzer if mTempPath is null

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

Change 657111 had a related patch set uploaded (by Jforrester; owner: Jforrester):
[mediawiki/core@REL1_35] UploadBase: Don't call MimeAnalyzer if mTempPath is null

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

Change 657111 merged by jenkins-bot:
[mediawiki/core@REL1_35] UploadBase: Don't call MimeAnalyzer if mTempPath is null

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