[BUGFIX] Illegal string offsets in t3lib_stdgraphic
authorWouter Wolters <typo3@wouterwolters.nl>
Sun, 28 Oct 2012 11:36:39 +0000 (12:36 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 2 Nov 2012 13:58:27 +0000 (14:58 +0100)
Change-Id: I8be45d59b780595e25d6d7f5371300b6506baa2f
Fixes: #38024
Releases: 6.0, 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/16132
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
t3lib/class.t3lib_stdgraphic.php
tests/t3lib/class.t3lib_stdgraphicTest.php [new file with mode: 0644]
typo3/sysext/cms/tslib/class.tslib_content.php
typo3/sysext/cms/tslib/showpic.php
typo3/sysext/install/mod/class.tx_install.php

index eaaadf5..f16ab36 100644 (file)
@@ -250,14 +250,14 @@ class t3lib_stdGraphic {
                        $imgInf = pathinfo($conf['file']);
                        $imgExt = strtolower($imgInf['extension']);
                        if (!t3lib_div::inList($this->gdlibExtensions, $imgExt)) {
-                               $BBimage = $this->imageMagickConvert($conf['file'], $this->gifExtension, '', '', '', '', '');
+                               $BBimage = $this->imageMagickConvert($conf['file'], $this->gifExtension);
                        } else {
                                $BBimage = $this->getImageDimensions($conf['file']);
                        }
                        $maskInf = pathinfo($conf['mask']);
                        $maskExt = strtolower($maskInf['extension']);
                        if (!t3lib_div::inList($this->gdlibExtensions, $maskExt)) {
-                               $BBmask = $this->imageMagickConvert($conf['mask'], $this->gifExtension, '', '', '', '', '');
+                               $BBmask = $this->imageMagickConvert($conf['mask'], $this->gifExtension);
                        } else {
                                $BBmask = $this->getImageDimensions($conf['mask']);
                        }
@@ -336,7 +336,7 @@ class t3lib_stdGraphic {
        function copyImageOntoImage(&$im, $conf, $workArea) {
                if ($conf['file']) {
                        if (!t3lib_div::inList($this->gdlibExtensions, $conf['BBOX'][2])) {
-                               $conf['BBOX'] = $this->imageMagickConvert($conf['BBOX'][3], $this->gifExtension, '', '', '', '', '');
+                               $conf['BBOX'] = $this->imageMagickConvert($conf['BBOX'][3], $this->gifExtension);
                                $conf['file'] = $conf['BBOX'][3];
                        }
                        $cpImg = $this->imageCreateFromFile($conf['file']);
@@ -1710,7 +1710,7 @@ class t3lib_stdGraphic {
                        $tmpStr = $this->randomName();
                        $theFile = $tmpStr . '.' . $this->gifExtension;
                        $this->ImageWrite($im, $theFile);
-                       $theNewFile = $this->imageMagickConvert($theFile, $this->gifExtension, $conf['width'], $conf['height'], $conf['params'], '', '');
+                       $theNewFile = $this->imageMagickConvert($theFile, $this->gifExtension, $conf['width'], $conf['height'], $conf['params']);
                        $tmpImg = $this->imageCreateFromFile($theNewFile[3]);
                        if ($tmpImg) {
                                ImageDestroy($im);
@@ -2115,7 +2115,7 @@ class t3lib_stdGraphic {
         * @return      array           [0]/[1] is w/h, [2] is file extension and [3] is the filename.
         * @see getImageScale(), typo3/show_item.php, fileList_ext::renderImage(), tslib_cObj::getImgResource(), SC_tslib_showpic::show(), maskImageOntoImage(), copyImageOntoImage(), scale()
         */
-       function imageMagickConvert($imagefile, $newExt = '', $w = '', $h = '', $params = '', $frame = '', $options = '', $mustCreate = 0) {
+       function imageMagickConvert($imagefile, $newExt = '', $w = '', $h = '', $params = '', $frame = '', $options = array(), $mustCreate = FALSE) {
                if ($this->NO_IMAGE_MAGICK) {
                                // Returning file info right away
                        return $this->getImageDimensions($imagefile);
@@ -2157,7 +2157,7 @@ class t3lib_stdGraphic {
                                if ($noScale && !$data['crs'] && !$params && !$frame && $newExt == $info[2] && !$mustCreate) {
                                                // set the new width and height before returning,
                                                // if the noScale option is set
-                                       if ($options['noScale']) {
+                                       if (!empty($options['noScale'])) {
                                                $info[0] = $data[0];
                                                $info[1] = $data[1];
                                        }
@@ -2357,7 +2357,7 @@ class t3lib_stdGraphic {
                $w = intval($w);
                $h = intval($h);
                        // if there are max-values...
-               if ($options['maxW']) {
+               if (!empty($options['maxW'])) {
                        if ($w) { // if width is given...
                                if ($w > $options['maxW']) {
                                        $w = $options['maxW'];
@@ -2370,7 +2370,7 @@ class t3lib_stdGraphic {
                                }
                        }
                }
-               if ($options['maxH']) {
+               if (!empty($options['maxH'])) {
                        if ($h) { // if height is given...
                                if ($h > $options['maxH']) {
                                        $h = $options['maxH'];
@@ -2428,13 +2428,13 @@ class t3lib_stdGraphic {
                $out[0] = $info[0];
                $out[1] = $info[1];
                        // Set minimum-measures!
-               if ($options['minW'] && $out[0] < $options['minW']) {
+               if (isset($options['minW']) && $out[0] < $options['minW']) {
                        if (($max || $crs) && $out[0]) {
                                $out[1] = round($out[1] * $options['minW'] / $out[0]);
                        }
                        $out[0] = $options['minW'];
                }
-               if ($options['minH'] && $out[1] < $options['minH']) {
+               if (isset($options['minH']) && $out[1] < $options['minH']) {
                        if (($max || $crs) && $out[1]) {
                                $out[0] = round($out[0] * $options['minH'] / $out[1]);
                        }
diff --git a/tests/t3lib/class.t3lib_stdgraphicTest.php b/tests/t3lib/class.t3lib_stdgraphicTest.php
new file mode 100644 (file)
index 0000000..88d4131
--- /dev/null
@@ -0,0 +1,132 @@
+<?php
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2012 Wouter Wolters <typo3@wouterwolters.nl>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Testcase for \TYPO3\CMS\Core\Imaging\GraphicalFunctions
+ *
+ * @package TYPO3
+ * @subpackage core
+ * @author Wouter Wolters <typo3@wouterwolters.nl>
+ */
+class t3lib_stdGraphicTest extends tx_phpunit_testcase {
+
+       /**
+        * @var \TYPO3\CMS\Core\Imaging\GraphicalFunctions
+        */
+       protected $fixture = NULL;
+
+       /**
+        * Set up
+        *
+        * @return void
+        */
+       public function setUp() {
+               $this->fixture = new t3lib_stdGraphic();
+       }
+
+       /**
+        * Tear down
+        *
+        * @return void
+        */
+       public function tearDown() {
+               $this->fixture = NULL;
+       }
+
+       /**
+        * Dataprovider for getScaleForImage
+        *
+        * @return array
+        */
+       public function getScaleForImageDataProvider() {
+               return array(
+                       'Get image scale for a width of 150px' => array(
+                               array(
+                                       170,
+                                       136,
+                               ),
+                               '150',
+                               '',
+                               array(),
+                               array(
+                                       'crs' => FALSE,
+                                       'origW' => 150,
+                                       'origH' => 0,
+                                       'max' => 0,
+                                       0 => 150,
+                                       1 => (float) 120
+                               ),
+                       ),
+                       'Get image scale with a maximum width of 100px' => array(
+                               array(
+                                       170,
+                                       136,
+                               ),
+                               '',
+                               '',
+                               array(
+                                       'maxW' => 100
+                               ),
+                               array(
+                                       'crs' => FALSE,
+                                       'origW' => 100,
+                                       'origH' => 0,
+                                       'max' => 1,
+                                       0 => 100,
+                                       1 => (float) 80
+                               ),
+                       ),
+                       'Get image scale with a minimum width of 200px' => array(
+                               array(
+                                       170,
+                                       136,
+                               ),
+                               '',
+                               '',
+                               array(
+                                       'minW' => 200
+                               ),
+                               array(
+                                       'crs' => FALSE,
+                                       'origW' => 0,
+                                       'origH' => 0,
+                                       'max' => 0,
+                                       0 => 200,
+                                       1 => (float) 136
+                               ),
+                       ),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider getScaleForImageDataProvider
+        */
+       public function getScaleForImage($info, $width, $height, $options, $expected) {
+               $result = $this->fixture->getImageScale($info, $width, $height, $options);
+               $this->assertEquals($result, $expected);
+       }
+}
+?>
\ No newline at end of file
index 4b3d50b..7dc5b2d 100644 (file)
@@ -1329,7 +1329,7 @@ class tslib_cObj {
                                        $gifCreator->init();
                                        $gifCreator->mayScaleUp = 0;
 
-                                       $dims = $gifCreator->getImageScale($gifCreator->getImageDimensions($imageFile), $conf['width'], $conf['height'], '');
+                                       $dims = $gifCreator->getImageScale($gifCreator->getImageDimensions($imageFile), $conf['width'], $conf['height'], array());
                                        $JSwindowExpand = isset($conf['JSwindow.']['expand.'])
                                                ? $this->stdWrap($conf['JSwindow.']['expand'], $conf['JSwindow.']['expand.'])
                                                : $conf['JSwindow.']['expand'];
@@ -5136,7 +5136,7 @@ class tslib_cObj {
                        $gifCreator = t3lib_div::makeInstance('tslib_gifbuilder');
                        /* @var $gifCreator tslib_gifbuilder */
                        $gifCreator->init();
-                       $info = $gifCreator->imageMagickConvert($theImage, 'WEB', '', '', '', '', '');
+                       $info = $gifCreator->imageMagickConvert($theImage, 'WEB');
                        $info['origFile'] = $theImage;
                        $info['origFile_mtime'] = @filemtime($theImage); // This is needed by tslib_gifbuilder, ln 100ff in order for the setup-array to create a unique filename hash.
                        $imageResource = $info;
index b37c2fc..db7abd2 100644 (file)
@@ -218,7 +218,7 @@ class SC_tslib_showpic {
                if ($this->frame) {
                        $this->frame = intval($this->frame);
                }
-               $imgInfo = $img->imageMagickConvert($this->file,'web',$this->width.$max,$this->height,$img->IMparams($this->effects),$this->frame,'');
+               $imgInfo = $img->imageMagickConvert($this->file,'web',$this->width.$max,$this->height,$img->IMparams($this->effects),$this->frame);
 
                        // Create HTML output:
                $this->content='';
@@ -263,4 +263,4 @@ $SOBE = t3lib_div::makeInstance('SC_tslib_showpic');
 $SOBE->init();
 $SOBE->main();
 $SOBE->printContent();
-?>
+?>
\ No newline at end of file
index cd6c971..0c0e0d5 100644 (file)
@@ -4572,7 +4572,7 @@ REMOTE_ADDR was '".t3lib_div::getIndpEnv('REMOTE_ADDR')."' (".t3lib_div::getIndp
                                                        if (!@is_file($theFile))        die('Error: '.$theFile.' was not a file');
 
                                                        $imageProc->imageMagickConvert_forceFileNameBody='read_'.$ext;
-                                                       $fileInfo = $imageProc->imageMagickConvert($theFile,'jpg',"",'',"",'',"",1);
+                                                       $fileInfo = $imageProc->imageMagickConvert($theFile, 'jpg', '', '', '', '', array(), TRUE);
                                                        $result = $this->displayTwinImage($fileInfo[3],$imageProc->IM_commands);
                                                        $this->message($headCode,"Read ".strtoupper($ext),$result[0],$result[1]);
                                                }
@@ -4584,7 +4584,7 @@ REMOTE_ADDR was '".t3lib_div::getIndpEnv('REMOTE_ADDR')."' (".t3lib_div::getIndp
                                                if (!@is_file($theFile))        die('Error: '.$theFile.' was not a file');
 
                                                $imageProc->imageMagickConvert_forceFileNameBody='read_pdf';
-                                               $fileInfo = $imageProc->imageMagickConvert($theFile,'jpg',"170",'',"",'',"",1);
+                                               $fileInfo = $imageProc->imageMagickConvert($theFile, 'jpg', '170', '', '', '', array(), TRUE);
                                                $result = $this->displayTwinImage($fileInfo[3],$imageProc->IM_commands);
                                                $this->message($headCode,'Read PDF',$result[0],$result[1]);
                                        }
@@ -4594,7 +4594,7 @@ REMOTE_ADDR was '".t3lib_div::getIndpEnv('REMOTE_ADDR')."' (".t3lib_div::getIndp
                                                if (!@is_file($theFile))        die('Error: '.$theFile.' was not a file');
 
                                                $imageProc->imageMagickConvert_forceFileNameBody='read_ai';
-                                               $fileInfo = $imageProc->imageMagickConvert($theFile,'jpg',"170",'',"",'',"",1);
+                                               $fileInfo = $imageProc->imageMagickConvert($theFile, 'jpg', '170', '', '', '', array(), TRUE);
                                                $result = $this->displayTwinImage($fileInfo[3],$imageProc->IM_commands);
                                                $this->message($headCode,'Read AI',$result[0],$result[1]);
                                        }
@@ -4632,7 +4632,7 @@ REMOTE_ADDR was '".t3lib_div::getIndpEnv('REMOTE_ADDR')."' (".t3lib_div::getIndp
                                        if (!@is_file($theFile))        die('Error: '.$theFile.' was not a file');
 
                                        $imageProc->imageMagickConvert_forceFileNameBody='write_gif';
-                                       $fileInfo = $imageProc->imageMagickConvert($theFile,'gif',"",'',"",'',"",1);
+                                       $fileInfo = $imageProc->imageMagickConvert($theFile, 'gif', '', '', '', '', array(), TRUE);
                                        if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gif_compress']) {
                                                clearstatcache();
                                                $prevSize=t3lib_div::formatSize(@filesize($fileInfo[3]));
@@ -4650,7 +4650,7 @@ REMOTE_ADDR was '".t3lib_div::getIndpEnv('REMOTE_ADDR')."' (".t3lib_div::getIndp
                                        $theFile = t3lib_extMgm::extPath('install').'imgs/jesus.gif';
 
                                        $imageProc->imageMagickConvert_forceFileNameBody='write_png';
-                                       $fileInfo = $imageProc->imageMagickConvert($theFile,'png',"",'',"",'',"",1);
+                                       $fileInfo = $imageProc->imageMagickConvert($theFile, 'png', '', '', '', '', array(), TRUE);
                                        $result = $this->displayTwinImage($fileInfo[3],$imageProc->IM_commands);
                                        $this->message($headCode,'Write PNG',$result[0],$result[1]);
                                } else {
@@ -4684,7 +4684,7 @@ REMOTE_ADDR was '".t3lib_div::getIndpEnv('REMOTE_ADDR')."' (".t3lib_div::getIndp
                                        if (!@is_file($theFile))        die('Error: '.$theFile.' was not a file');
 
                                        $imageProc->imageMagickConvert_forceFileNameBody='scale_gif';
-                                       $fileInfo = $imageProc->imageMagickConvert($theFile,'gif',"150",'',"",'',"",1);
+                                       $fileInfo = $imageProc->imageMagickConvert($theFile, 'gif', '150', '', '', '', array(), TRUE);
                                        if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gif_compress']) {
                                                clearstatcache();
                                                $prevSize=t3lib_div::formatSize(@filesize($fileInfo[3]));
@@ -4701,7 +4701,7 @@ REMOTE_ADDR was '".t3lib_div::getIndpEnv('REMOTE_ADDR')."' (".t3lib_div::getIndp
                                        if (!@is_file($theFile))        die('Error: '.$theFile.' was not a file');
 
                                        $imageProc->imageMagickConvert_forceFileNameBody='scale_png';
-                                       $fileInfo = $imageProc->imageMagickConvert($theFile,'png',"150",'',"",'',"",1);
+                                       $fileInfo = $imageProc->imageMagickConvert($theFile, 'png', '150', '', '', '', array(), TRUE);
                                        $result = $this->displayTwinImage($fileInfo[3],$imageProc->IM_commands);
                                        $this->message($headCode,'PNG to PNG, 150 pixels wide',$result[0],$result[1]);
 
@@ -4709,7 +4709,7 @@ REMOTE_ADDR was '".t3lib_div::getIndpEnv('REMOTE_ADDR')."' (".t3lib_div::getIndp
                                        $theFile = t3lib_extMgm::extPath('install').'imgs/jesus2_transp.gif';
                                        if (!@is_file($theFile))        die('Error: '.$theFile.' was not a file');
                                        $imageProc->imageMagickConvert_forceFileNameBody='scale_jpg';
-                                       $fileInfo = $imageProc->imageMagickConvert($theFile,'jpg',"150",'',"",'',"",1);
+                                       $fileInfo = $imageProc->imageMagickConvert($theFile, 'jpg', '150', '', '', '', array(), TRUE);
                                        $result = $this->displayTwinImage($fileInfo[3],$imageProc->IM_commands);
                                        $this->message($headCode,'GIF to JPG, 150 pixels wide',$result[0],$result[1]);
                                } else {