MediaWiki r32393 - Code Review

Jump to: navigation, search
Repository:MediaWiki
Revision:r32392‎ | r32393 (on ViewVC)‎ | r32394 >
Date:04:26, 25 March 2008
Author:tstarling
Status:old
Tags:
Comment:
Stack depth limit for expand()
Modified paths:

Diff [purge]

Index: trunk/phase3/includes/Preprocessor_DOM.php
===================================================================
--- trunk/phase3/includes/Preprocessor_DOM.php	(revision 32392)
+++ trunk/phase3/includes/Preprocessor_DOM.php	(revision 32393)
@@ -811,6 +811,7 @@
 	}
 
 	function expand( $root, $flags = 0 ) {
+		static $depth = 0;
 		if ( is_string( $root ) ) {
 			return $root;
 		}
@@ -820,6 +821,11 @@
 			return '<span class="error">Node-count limit exceeded</span>';
 		}
 
+		if ( $depth > $this->parser->mOptions->mMaxPPExpandDepth ) {
+			return '<span class="error">Expansion depth limit exceeded</span>';
+		}
+		++$depth;
+
 		if ( $root instanceof PPNode_DOM ) {
 			$root = $root->node;
 		}
@@ -1006,6 +1012,7 @@
 				}
 			}
 		}
+		--$depth;
 		return $outStack[0];
 	}
 
Index: trunk/phase3/includes/Preprocessor_Hash.php
===================================================================
--- trunk/phase3/includes/Preprocessor_Hash.php	(revision 32392)
+++ trunk/phase3/includes/Preprocessor_Hash.php	(revision 32393)
@@ -804,6 +804,10 @@
 		{
 			return '<span class="error">Node-count limit exceeded</span>';
 		}
+		if ( $depth > $this->parser->mOptions->mMaxPPExpandDepth ) {
+			return '<span class="error">Expansion depth limit exceeded</span>';
+		}
+		++$depth;
 
 		$outStack = array( '', '' );
 		$iteratorStack = array( false, $root );
@@ -956,6 +960,7 @@
 				}
 			}
 		}
+		--$depth;
 		return $outStack[0];
 	}
 
Index: trunk/phase3/includes/DefaultSettings.php
===================================================================
--- trunk/phase3/includes/DefaultSettings.php	(revision 32392)
+++ trunk/phase3/includes/DefaultSettings.php	(revision 32393)
@@ -920,6 +920,7 @@
  * stop the parser before it hits the xdebug limit.
  */
 $wgMaxTemplateDepth = 40;
+$wgMaxPPExpandDepth = 40;
 
 $wgExtraSubtitle	= '';
 $wgSiteSupportPage	= ''; # A page where you users can receive donations
@@ -2961,4 +2962,4 @@
  * Maximum number of links to a redirect page listed on
  * Special:Whatlinkshere/RedirectDestination
  */
-$wgMaxRedirectLinksRetrieved = 500;
\ No newline at end of file
+$wgMaxRedirectLinksRetrieved = 500;
Index: trunk/phase3/includes/ParserOptions.php
===================================================================
--- trunk/phase3/includes/ParserOptions.php	(revision 32392)
+++ trunk/phase3/includes/ParserOptions.php	(revision 32393)
@@ -23,6 +23,7 @@
 	var $mTargetLanguage;            # Overrides above setting with arbitrary language
 	var $mMaxIncludeSize;            # Maximum size of template expansions, in bytes
 	var $mMaxPPNodeCount;            # Maximum number of nodes touched by PPFrame::expand()
+	var $mMaxPPExpandDepth;          # Maximum recursion depth in PPFrame::expand()
 	var $mMaxTemplateDepth;          # Maximum recursion depth for templates within templates
 	var $mRemoveComments;            # Remove HTML comments. ONLY APPLIES TO PREPROCESS OPERATIONS
 	var $mTemplateCallback;          # Callback for template fetching
@@ -107,7 +108,7 @@
 	function initialiseFromUser( $userInput ) {
 		global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
 		global $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion, $wgMaxArticleSize;
-		global $wgMaxPPNodeCount, $wgMaxTemplateDepth;
+		global $wgMaxPPNodeCount, $wgMaxTemplateDepth, $wgMaxPPExpandDepth;
 		$fname = 'ParserOptions::initialiseFromUser';
 		wfProfileIn( $fname );
 		if ( !$userInput ) {
@@ -138,6 +139,7 @@
 		$this->mTargetLanguage = null; // default depends on InterfaceMessage setting
 		$this->mMaxIncludeSize = $wgMaxArticleSize * 1024;
 		$this->mMaxPPNodeCount = $wgMaxPPNodeCount;
+		$this->mMaxPPExpandDepth = $wgMaxPPExpandDepth;
 		$this->mMaxTemplateDepth = $wgMaxTemplateDepth;
 		$this->mRemoveComments = true;
 		$this->mTemplateCallback = array( 'Parser', 'statelessFetchTemplate' );

Status & tagging log

  • 15:25, 12 September 2011 Meno25 (Talk | contribs) changed the status of r32393 [removed: ok added: old]
Personal tools
Namespaces
Variants
Views
Actions
Site
Support
Download
Development
Communication
Toolbox