From: Tim Starling Date: Wed, 27 Sep 2006 00:43:37 +0000 (+0000) Subject: Added file size limit for all shell processes, to stop ImageMagick from writing out... X-Git-Tag: 1.31.0-rc.0~55711 X-Git-Url: http://git.cyclocoop.org/%22%2C%20generer_url_ecrire%28?a=commitdiff_plain;h=ae7de9eb53aa14ac6a044256fb4b2b1d7056119d;p=lhc%2Fweb%2Fwiklou.git Added file size limit for all shell processes, to stop ImageMagick from writing out gigabytes of scratch files. It uses a deceptively low amount of CPU time while it does this, meaning that it can significantly slow down server performance for many minutes. --- diff --git a/bin/ulimit-tvf.sh b/bin/ulimit-tvf.sh new file mode 100755 index 0000000000..8a1eb81c60 --- /dev/null +++ b/bin/ulimit-tvf.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +ulimit -t $1 -v $2 -f $3 +shift 3 +"$@" + diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 7375be9443..f7be878475 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -2201,6 +2201,12 @@ $wgContentNamespaces = array( NS_MAIN ); */ $wgMaxShellMemory = 102400; +/** + * Maximum file size created by shell processes under linux, in KB + * ImageMagick convert for example can be fairly hungry for scratch space + */ +$wgMaxShellFileSize = 102400; + /** * DJVU settings * Path of the djvutoxml executable diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 3079fba7af..c1a99069f5 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1671,7 +1671,7 @@ function wfUrlProtocols() { * @return collected stdout as a string (trailing newlines stripped) */ function wfShellExec( $cmd, &$retval=null ) { - global $IP, $wgMaxShellMemory; + global $IP, $wgMaxShellMemory, $wgMaxShellFileSize; if( ini_get( 'safe_mode' ) ) { wfDebug( "wfShellExec can't run in safe_mode, PHP's exec functions are too broken.\n" ); @@ -1682,11 +1682,12 @@ function wfShellExec( $cmd, &$retval=null ) { if ( php_uname( 's' ) == 'Linux' ) { $time = ini_get( 'max_execution_time' ); $mem = intval( $wgMaxShellMemory ); + $filesize = intval( $wgMaxShellFileSize ); if ( $time > 0 && $mem > 0 ) { - $script = "$IP/bin/ulimit.sh"; + $script = "$IP/bin/ulimit-tvf.sh"; if ( is_executable( $script ) ) { - $cmd = escapeshellarg( $script ) . " $time $mem $cmd"; + $cmd = escapeshellarg( $script ) . " $time $mem $filesize $cmd"; } } } elseif ( php_uname( 's' ) == 'Windows NT' ) {