Import: Importing no longer accepts too big revisions
authorThis, that and the other <at.light@live.com.au>
Wed, 23 Dec 2015 09:31:37 +0000 (20:31 +1100)
committerThis, that and the other <at.light@live.com.au>
Wed, 23 Dec 2015 09:31:37 +0000 (20:31 +1100)
Make sure the size of imported revisions does not exceed $wgMaxArticleSize.

Bug: T73230
Change-Id: I6addace7d0eae565196bba564fbd1e329b681064

includes/Import.php

index 0999931..67f7ba5 100644 (file)
@@ -825,6 +825,30 @@ class WikiImporter {
         * @return bool|mixed
         */
        private function processRevision( $pageInfo, $revisionInfo ) {
+               global $wgMaxArticleSize;
+
+               // Make sure revisions won't violate $wgMaxArticleSize, which could lead to
+               // database errors and instability. Testing for revisions with only listed
+               // content models, as other content models might use serialization formats
+               // which aren't checked against $wgMaxArticleSize.
+               if ( ( !isset( $revisionInfo['model'] ) ||
+                       in_array( $revisionInfo['model'], array(
+                               'wikitext',
+                               'css',
+                               'json',
+                               'javascript',
+                               'text',
+                               ''
+                       ) ) ) &&
+                       (int)( strlen( $revisionInfo['text'] ) / 1024 ) > $wgMaxArticleSize
+               ) {
+                       throw new MWException( 'The text of ' .
+                               ( isset( $revisionInfo['id'] ) ?
+                                       "the revision with ID $revisionInfo[id]" :
+                                       'a revision'
+                               ) . " exceeds the maximum allowable size ($wgMaxArticleSize KB)" );
+               }
+
                $revision = new WikiRevision( $this->config );
 
                if ( isset( $revisionInfo['id'] ) ) {