Generated node count limit
[lhc/web/wiklou.git] / includes / parser / Preprocessor_DOM.php
index e75237b..34de0ba 100644 (file)
@@ -162,6 +162,15 @@ class Preprocessor_DOM implements Preprocessor {
                        }
 
                }
+
+               // Fail if the number of elements exceeds acceptable limits
+               // Do not attempt to generate the DOM 
+               $this->parser->mGeneratedPPNodeCount += substr_count( $xml, '<' );
+               $max = $this->parser->mOptions->getMaxGeneratedPPNodeCount();
+               if ( $this->parser->mGeneratedPPNodeCount > $max ) {
+                       throw new MWException( __METHOD__.': generated node count limit exceeded' );
+               }
+
                wfProfileIn( __METHOD__.'-loadXML' );
                $dom = new DOMDocument;
                wfSuppressWarnings();