Bounded execution time and memory for image thumbnailing
authorTim Starling <tstarling@users.mediawiki.org>
Sat, 26 Nov 2005 05:36:34 +0000 (05:36 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Sat, 26 Nov 2005 05:36:34 +0000 (05:36 +0000)
includes/GlobalFunctions.php
includes/Image.php

index b4be648..d97740e 100644 (file)
@@ -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 );
index 8d3709a..c1ca218 100644 (file)
@@ -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.
                        #