From c48b61c01b48b0af079a46b1a6767b387adc02fe Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Thu, 29 Sep 2011 19:00:45 +0000 Subject: [PATCH] (bug 30202) Restrict file names on upload to 240 bytes, because wfTimestamp( TS_MW ) . '!' . $fileName should fit in oi_archive_name, which is 255 bytes, and also the maximum file name length on many file systems is 255 bytes. Commit to fix UploadTest to use @dataProvider will follow --- RELEASE-NOTES-1.19 | 2 ++ includes/upload/UploadBase.php | 8 ++++++++ tests/phpunit/includes/upload/UploadTest.php | 11 +++++++++++ 3 files changed, 21 insertions(+) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 08dc004a7c..60df92b40a 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -107,6 +107,8 @@ production. * Per page edit-notices now work in namespaces without subpages enabled. * (bug 30245) Use the correct way to construct a log page title * (bug 31081) $wgEnotifUseJobQ causes many unnecessary jobs to be queued +* (bug 30202) File names are now restricted on upload to 240 bytes, because of + restrictions on some of the database fields. === API changes in 1.19 === * (bug 19838) siprop=interwikimap can now use the interwiki cache. diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 6fa72f8d3d..3c66086f50 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -631,6 +631,14 @@ abstract class UploadBase { } $this->mFilteredName = $nt->getDBkey(); + # oi_archive_name is max 255 bytes, which include a timestamp and an + # exclamation mark, so restrict file name to 240 bytes. Return + # ILLEGAL_FILENAME, just like would have happened for >255 bytes + if ( strlen( $this->mFilteredName ) > 240 ) { + $this->mTitleError = self::ILLEGAL_FILENAME; + return $this->mTitle = null; + } + /** * We'll want to blacklist against *any* 'extension', and use * only the final one for the whitelist. diff --git a/tests/phpunit/includes/upload/UploadTest.php b/tests/phpunit/includes/upload/UploadTest.php index 69c2903294..f74018a5a4 100644 --- a/tests/phpunit/includes/upload/UploadTest.php +++ b/tests/phpunit/includes/upload/UploadTest.php @@ -60,6 +60,16 @@ class UploadTest extends MediaWikiTestCase { $this->assertUploadTitleAndCode( '.jpg', null, UploadBase::MIN_LENGTH_PARTNAME, 'upload title without basename' ); + + /* A title that is longer than 255 bytes */ + $this->assertUploadTitleAndCode( str_repeat( 'a', 255 ) . '.jpg', + null, UploadBase::ILLEGAL_FILENAME, + 'upload title longer than 255 bytes' ); + + /* A title that is longer than 240 bytes */ + $this->assertUploadTitleAndCode( str_repeat( 'a', 240 ) . '.jpg', + null, UploadBase::ILLEGAL_FILENAME, + 'upload title longer than 240 bytes' ); } /** @@ -134,6 +144,7 @@ class UploadTestHandler extends UploadBase { public function testTitleValidation( $name ) { $this->mTitle = false; $this->mDesiredDestName = $name; + $this->mTitleError = UploadBase::OK; $this->getTitle(); return $this->mTitleError; } -- 2.20.1