Merge "Revert "Added some constants to speed up Setup.php""
[lhc/web/wiklou.git] / includes / upload / UploadBase.php
index 4c8148a..67bffc3 100644 (file)
@@ -474,9 +474,10 @@ abstract class UploadBase {
                                return array( 'uploadscripted' );
                        }
                        if ( $this->mFinalExtension == 'svg' || $mime == 'image/svg+xml' ) {
-                               if ( $this->detectScriptInSvg( $this->mTempPath ) ) {
+                               $svgStatus = $this->detectScriptInSvg( $this->mTempPath );
+                               if ( $svgStatus !== false ) {
                                        wfProfileOut( __METHOD__ );
-                                       return array( 'uploadscripted' );
+                                       return $svgStatus;
                                }
                        }
                }
@@ -1164,11 +1165,36 @@ abstract class UploadBase {
 
        /**
         * @param $filename string
-        * @return bool
+        * @return mixed false of the file is verified (does not contain scripts), array otherwise.
         */
        protected function detectScriptInSvg( $filename ) {
-               $check = new XmlTypeCheck( $filename, array( $this, 'checkSvgScriptCallback' ) );
-               return $check->filterMatch;
+               $check = new XmlTypeCheck(
+                       $filename,
+                       array( $this, 'checkSvgScriptCallback' ),
+                       true,
+                       array( 'processing_instruction_handler' => 'UploadBase::checkSvgPICallback' )
+               );
+               if ( $check->wellFormed !== true ) {
+                       // Invalid xml (bug 58553)
+                       return array( 'uploadinvalidxml' );
+               } elseif ( $check->filterMatch ) {
+                       return array( 'uploadscripted' );
+               }
+               return false;
+       }
+
+       /**
+        * Callback to filter SVG Processing Instructions.
+        * @param $target string processing instruction name
+        * @param $data string processing instruction attribute and value
+        * @return bool (true if the filter identified something bad)
+        */
+       public static function checkSvgPICallback( $target, $data ) {
+               // Don't allow external stylesheets (bug 57550)
+               if ( preg_match( '/xml-stylesheet/i', $target) ) {
+                       return true;
+               }
+               return false;
        }
 
        /**