Index: t3lib/class.t3lib_div.php =================================================================== --- t3lib/class.t3lib_div.php (revision 10435) +++ t3lib/class.t3lib_div.php (working copy) @@ -5953,10 +5953,23 @@ // Compile the path & command if($im_version==='gm') { $switchCompositeParameters=true; - $path = escapeshellarg($path . 'gm' . $isExt) . ' ' . $command; + $originalPath = $path . 'gm' . $isExt; + $path = escapeshellarg($originalPath); + // if escapeshellarg didn't change anything or if there is no whitespace in the original string + // keep the original for (partial) safe_mode compatibility + if (trim($path, '"\'') == $originalPath && !preg_match('/[[:space:]]/', $originalPath)) { + $path = $originalPath; + } + $path .= ' ' . $command; } else { if($im_version==='im6') { $switchCompositeParameters=true; } - $path = escapeshellarg($path . (($command == 'composite') ? $combineScript : $command) . $isExt); + $originalPath = $path . (($command == 'composite') ? $combineScript : $command) . $isExt; + $path = escapeshellarg($originalPath); + // if escapeshellarg didn't change anything or if there is no whitespace in the original string + // keep the original for (partial) safe_mode compatibility + if (trim($path, '"\'') == $originalPath && !preg_match('/[[:space:]]/', $originalPath)) { + $path = $originalPath; + } } // strip profile information for thumbnails and reduce their size Index: t3lib/class.t3lib_stdgraphic.php =================================================================== --- t3lib/class.t3lib_stdgraphic.php (revision 10435) +++ t3lib/class.t3lib_stdgraphic.php (working copy) @@ -2728,7 +2728,13 @@ * @return string $inputName escaped as needed */ protected function wrapFileName($inputName) { - return escapeshellarg($inputName); + $escapedInputName = escapeshellarg($inputName); + // if escapeshellarg didn't change anything or if there is no whitespace in the original string + // keep the original for (partial) safe_mode compatibility + if (trim($escapedInputName, '"\'') == $inputName && !preg_match('/[[:space:]]/', $inputName)) { + $escapedInputName = $inputName; + } + return $escapedInputName; } Index: t3lib/thumbs.php =================================================================== --- t3lib/thumbs.php (revision 10435) +++ t3lib/thumbs.php (working copy) @@ -397,7 +397,13 @@ * @return string $inputName escaped as needed */ protected function wrapFileName($inputName) { - return escapeshellarg($inputName); + $escapedInputName = escapeshellarg($inputName); + // if escapeshellarg didn't change anything or if there is no whitespace in the original string + // keep the original for (partial) safe_mode compatibility + if (trim($escapedInputName, '"\'') == $inputName && !preg_match('/[[:space:]]/', $inputName)) { + $escapedInputName = $inputName; + } + return $escapedInputName; } }