Update of /cvsroot/php-blog/serendipity/include
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16576/include
Modified Files:
functions_images.inc.php
Log Message:
- Fix imagick not rotating in the right direction (apparently gdlib and imagick doesn't agree on which direction to rotate in)
- Escape arguments and commands used when executing imagick, to avoid evil command injections
- Emit error if imagick execution failed
- Don't echo that we've created a thumbnail, when the creation failed
Index: functions_images.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/functions_images.inc.php,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- functions_images.inc.php 3 Feb 2005 18:55:17 -0000 1.27
+++ functions_images.inc.php 6 Feb 2005 01:04:52 -0000 1.28
@@ -212,24 +212,25 @@
if ($serendipity['magick'] !== true) {
$r = serendipity_resize_image_gd($infile, $outfile, $size);
} else {
- /*if ($serendipity["dim"] == "height") $newSize = "*x".$serendipity["thumbSize"];
- else $newSize = $serendipity["thumbSize"]."x*"; */
+ $r = array($size, $size);
+ $newSize = $size . 'x' . $size;
if ($ft_mime != 'application/pdf') {
- $newSize = $size . 'x' . $size;
- $r = array($size, $size);
- $cmd = $serendipity['convert'] . " -antialias -scale $newSize \"$infile\" \"$outfile\" 2>&1";
+ $cmd = escapeshellcmd($serendipity['convert']) . ' -antialias -scale '. escapeshellarg($newSize) .' '. escapeshellarg($infile) .' '. escapeshellarg($outfile);
} else {
- $newSize = $size . 'x' . $size;
- $cmd = $serendipity['convert'] . " -antialias -flatten -scale $newSize \"$infile\" \"$outfile.png\" 2>&1";
- echo $cmd;
+ $cmd = escapeshellcmd($serendipity['convert']) . ' -antialias -flatten -scale '. escapeshellarg($newSize) .' '. escapeshellarg($infile) .' '. escapeshellarg($outfile .'.png');
}
- $res = `$cmd`;
+ exec($cmd, $output, $result);
+ if ( $result != 0 ) {
+ echo '<div class="serendipityAdminMsgError">'. sprintf(IMAGICK_EXEC_ERROR, $cmd, $output[0], $result) .'</div>';
+ $r = false; // return failure
+ }
+ unset($output, $result);
}
}
/* Lets assume we are all done, now we add the image to the image database */
if ($insertMode) {
- $r['image_id'] = serendipity_insertImageInDatabase($f, $suf, $fdim['mime'], filesize($infile), $fdim[0], $fdim[1], $serendipity['thumbSuffix'], time(), $authorid, $directory);
+ serendipity_insertImageInDatabase($f, $suf, $fdim['mime'], filesize($infile), $fdim[0], $fdim[1], $serendipity['thumbSuffix'], time(), $authorid, $directory);
}
return $r;
@@ -245,7 +246,6 @@
$admin = '';
if ($serendipity['serendipityUserlevel'] < USERLEVEL_CHIEF && $file['authorid'] != '0' && $file['authorid'] != $serendipity['authorid']) {
- // A non-admin user may not delete private files from other users.
return;
}
@@ -254,12 +254,16 @@
if ($serendipity['magick'] !== true) {
serendipity_resize_image_gd($infile, $outfile, $width, $height);
} else {
- $cmd = $serendipity['convert'] . ' -scale ' . $width . 'x' . $height . ' ' . $infile . ' ' . $outfile;
- $res = `$cmd`;
+ $cmd = escapeshellcmd($serendipity['convert']) . ' -scale ' . escapeshellarg($width . 'x' . $height) . ' ' . escapeshellarg($infile) . ' ' . escapeshellarg($outfile);
+ exec($cmd, $output, $result);
+ if ( $result != 0 ) {
+ echo '<div class="serendipityAdminMsgError">'. sprintf(IMAGICK_EXEC_ERROR, $cmd, $output[0], $result) .'</div>';
+ }
+ unset($output, $result);
}
serendipity_updateImageInDatabase(array('dimensions_width' => $width, 'dimensions_height' => $height), $id);
- return;
+ return true;
}
/**
@@ -283,10 +287,25 @@
serendipity_rotate_image_gd($infile, $outfile, $degrees);
serendipity_rotate_image_gd($infileThumb, $outfileThumb, $degrees);
} else {
- $cmd = $serendipity['convert'] . ' -rotate ' . $degrees . ' ' . $infile . ' ' . $outfile;
- $res = `$cmd`;
- $cmdThumb = $serendipity['convert'] . ' -rotate ' . $degrees . ' ' . $infileThumb . ' ' . $outfileThumb;
- $resThumb = `$cmdThumb`;
+ /* Why can't we just all agree on the rotation direction? */
+ $degrees = (360 - $degrees);
+
+ /* Resize main image */
+ $cmd = escapeshellcmd($serendipity['convert']) . ' -rotate ' . escapeshellarg($degrees) . ' ' . escapeshellarg($infile) . ' ' . escapeshellarg($outfile);
+ exec($cmd, $output, $result);
+ if ( $result != 0 ) {
+ echo '<div class="serendipityAdminMsgError">'. sprintf(IMAGICK_EXEC_ERROR, $cmd, $output[0], $result) .'</div>';
+ }
+ unset($output, $result);
+
+ /* Resize thumbnail */
+ $cmd = escapeshellcmd($serendipity['convert']) . ' -rotate ' . escapeshellarg($degrees) . ' ' . escapeshellarg($infileThumb) . ' ' . escapeshellarg($outfileThumb);
+ exec($cmd, $output, $result);
+ if ( $result != 0 ) {
+ echo '<div class="serendipityAdminMsgError">'. sprintf(IMAGICK_EXEC_ERROR, $cmd, $output[0], $result) .'</div>';
+ }
+ unset($output, $result);
+
}
$fdim = @getimagesize($outfile);
@@ -347,9 +366,7 @@
if ($update) {
$i++;
- $updates = array(
- 'thumbnail_name' => $serendipity['thumbSuffix']
- );
+ $updates = array('thumbnail_name' => $serendipity['thumbSuffix']);
serendipity_updateImageInDatabase($updates, $file['id']);
}
} else {
|