From ae7de9eb53aa14ac6a044256fb4b2b1d7056119d Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Wed, 27 Sep 2006 00:43:37 +0000 Subject: [PATCH] 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. --- bin/ulimit-tvf.sh | 6 ++++++ includes/DefaultSettings.php | 6 ++++++ includes/GlobalFunctions.php | 7 ++++--- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100755 bin/ulimit-tvf.sh 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' ) { -- 2.20.1