From 1c93c62945b42a1d5db949eb0d4c3f1a2d1d2b84 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Sat, 26 Nov 2005 05:36:34 +0000 Subject: [PATCH] Bounded execution time and memory for image thumbnailing --- includes/GlobalFunctions.php | 8 ++++++-- includes/Image.php | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index b4be6488ae..d97740eba9 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1584,12 +1584,16 @@ function wfIsWellFormedXmlFragment( $text ) { function wfShellExec( $cmd ) { global $IP; + if ( php_uname( 's' ) == 'Linux' ) { $time = ini_get( 'max_execution_time' ); $mem = ini_get( 'memory_limit' ); if ( $time > 0 && $mem > 0 ) { - $memKB = intval( $mem / 1024 ); - $cmd = escapeshellarg( "$IP/bin/ulimit.sh" ) . " $time $memKB $cmd"; + $script = "$IP/bin/ulimit.sh"; + if ( is_executable( $script ) ) { + $memKB = intval( $mem / 1024 ); + $cmd = escapeshellarg( $script ) . " $time $memKB $cmd"; + } } } return shell_exec( $cmd ); diff --git a/includes/Image.php b/includes/Image.php index 8d3709a21d..c1ca2187d6 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -1036,7 +1036,7 @@ class Image wfEscapeShellArg( $thumbPath ) ), $wgSVGConverters[$wgSVGConverter] ); wfDebug( "reallyRenderThumb SVG: $cmd\n" ); - $conv = shell_exec( $cmd ); + $conv = wfShellExec( $cmd ); } else { $conv = false; } @@ -1049,7 +1049,7 @@ class Image wfEscapeShellArg($this->imagePath) . " -resize {$width}x{$height} " . wfEscapeShellArg($thumbPath); wfDebug("reallyRenderThumb: running ImageMagick: $cmd\n"); - $conv = shell_exec( $cmd ); + $conv = wfShellExec( $cmd ); } else { # Use PHP's builtin GD library functions. # -- 2.20.1