Ticket #1906: 1906.patch

File 1906.patch, 2.3 kB (added by wwalc, 4 months ago)
  • editor/filemanager/connectors/php/commands.php

     
    184184 
    185185                if ( isset( $Config['SecureImageUploads'] ) ) 
    186186                { 
    187                         if ( !IsImageValid( $oFile['tmp_name'], $sExtension ) ) 
     187                        if ( ( $isImageValid = IsImageValid( $oFile['tmp_name'], $sExtension ) ) === false ) 
    188188                        { 
    189189                                $sErrorNumber = '202' ; 
    190190                        } 
     
    192192 
    193193                if ( isset( $Config['HtmlExtensions'] ) ) 
    194194                { 
    195                         if ( !IsHtmlExtension( $sExtension, $Config['HtmlExtensions'] ) && DetectHtml( $oFile['tmp_name'] ) ) 
     195                        if ( !IsHtmlExtension( $sExtension, $Config['HtmlExtensions'] ) &&  
     196                                ( $detectHtml = DetectHtml( $oFile['tmp_name'] ) ) === true ) 
    196197                        { 
    197198                                $sErrorNumber = '202' ; 
    198199                        } 
     
    227228                                        break ; 
    228229                                } 
    229230                        } 
     231                         
     232                        if ( file_exists( $sFilePath ) ) 
     233                        { 
     234                                //previous checks failed, try once again 
     235                                if ( isset( $isImageValid ) && $isImageValid === -1 && IsImageValid( $sFilePath, $sExtension ) === false ) 
     236                                { 
     237                                        @unlink( $sFilePath ) ; 
     238                                        $sErrorNumber = '202' ; 
     239                                }                                        
     240                                if ( isset( $detectHtml ) && $detectHtml === -1 && DetectHtml( $sFilePath ) === true ) 
     241                                { 
     242                                        @unlink( $sFilePath ) ; 
     243                                        $sErrorNumber = '202' ;                                  
     244                                }                                
     245                        } 
    230246                } 
    231247                else 
    232248                        $sErrorNumber = '202' ; 
  • editor/filemanager/connectors/php/util.php

     
    8686 */ 
    8787function DetectHtml( $filePath ) 
    8888{ 
    89         $fp = fopen( $filePath, 'rb' ) ; 
     89        $fp = @fopen( $filePath, 'rb' ) ; 
     90         
     91        //open_basedir restriction, see #1906 
     92        if ( $fp === false || !flock( $fp, LOCK_SH ) ) 
     93        { 
     94                return -1 ; 
     95        } 
     96                 
    9097        $chunk = fread( $fp, 1024 ) ; 
     98        flock( $fp, LOCK_UN ) ; 
    9199        fclose( $fp ) ; 
    92100 
    93101        $chunk = strtolower( $chunk ) ; 
     
    149157 */ 
    150158function IsImageValid( $filePath, $extension ) 
    151159{ 
     160        if (!@is_readable($filePath)) { 
     161                return -1; 
     162        } 
     163         
    152164        $imageCheckExtensions = array('gif', 'jpeg', 'jpg', 'png', 'swf', 'psd', 'bmp', 'iff'); 
    153165 
    154166        // version_compare is available since PHP4 >= 4.0.7