[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:16:17 +0000 (14:16 +0100)
Illegal string offsets in t3lib_stdgraphic

Change-Id: I8be45d59b780595e25d6d7f5371300b6506baa2f
Fixes: #38024
Releases: 6.0, 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/12543
Reviewed-by: Stefan Neufeind
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php
typo3/sysext/core/Tests/Unit/Imaging/GraphicalFunctionsTest.php [new file with mode: 0644]
typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php
typo3/sysext/frontend/Classes/Controller/ShowImageController.php
typo3/sysext/install/Classes/Installer.php

index 5279e4c..e35619e 100644 (file)
@@ -386,14 +386,14 @@ class GraphicalFunctions {
                        $imgInf = pathinfo($conf['file']);
                        $imgExt = strtolower($imgInf['extension']);
                        if (!\TYPO3\CMS\Core\Utility\GeneralUtility::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 (!\TYPO3\CMS\Core\Utility\GeneralUtility::inList($this->gdlibExtensions, $maskExt)) {
-                               $BBmask = $this->imageMagickConvert($conf['mask'], $this->gifExtension, '', '', '', '', '');
+                               $BBmask = $this->imageMagickConvert($conf['mask'], $this->gifExtension);
                        } else {
                                $BBmask = $this->getImageDimensions($conf['mask']);
                        }
@@ -471,7 +471,7 @@ class GraphicalFunctions {
        public function copyImageOntoImage(&$im, $conf, $workArea) {
                if ($conf['file']) {
                        if (!\TYPO3\CMS\Core\Utility\GeneralUtility::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']);
@@ -1795,7 +1795,7 @@ class GraphicalFunctions {
                        $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);
@@ -2203,7 +2203,7 @@ class GraphicalFunctions {
         * @see getImageScale(), typo3/show_item.php, fileList_ext::renderImage(), tslib_cObj::getImgResource(), SC_tslib_showpic::show(), maskImageOntoImage(), copyImageOntoImage(), scale()
         * @todo Define visibility
         */
-       public function imageMagickConvert($imagefile, $newExt = '', $w = '', $h = '', $params = '', $frame = '', $options = '', $mustCreate = 0) {
+       public 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);
@@ -2242,7 +2242,7 @@ class GraphicalFunctions {
                                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];
                                        }
@@ -2418,7 +2418,7 @@ class GraphicalFunctions {
                $w = intval($w);
                $h = intval($h);
                // If there are max-values...
-               if ($options['maxW']) {
+               if (!empty($options['maxW'])) {
                        // If width is given...
                        if ($w) {
                                if ($w > $options['maxW']) {
@@ -2434,7 +2434,7 @@ class GraphicalFunctions {
                                }
                        }
                }
-               if ($options['maxH']) {
+               if (!empty($options['maxH'])) {
                        // If height is given...
                        if ($h) {
                                if ($h > $options['maxH']) {
@@ -2496,13 +2496,13 @@ class GraphicalFunctions {
                $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/typo3/sysext/core/Tests/Unit/Imaging/GraphicalFunctionsTest.php b/typo3/sysext/core/Tests/Unit/Imaging/GraphicalFunctionsTest.php
new file mode 100644 (file)
index 0000000..4bf26b9
--- /dev/null
@@ -0,0 +1,133 @@
+<?php
+namespace TYPO3\CMS\Core\Tests\Unit\Imaging;
+
+/***************************************************************
+ *  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 GraphicalFunctionsTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @var \TYPO3\CMS\Core\Imaging\GraphicalFunctions
+        */
+       protected $fixture = NULL;
+
+       /**
+        * Set up
+        *
+        * @return void
+        */
+       public function setUp() {
+               $this->fixture = new \TYPO3\CMS\Core\Imaging\GraphicalFunctions();
+       }
+
+       /**
+        * 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 4a3f4dc..bbfa894 100644 (file)
@@ -1431,7 +1431,7 @@ class ContentObjectRenderer {
                                        $gifCreator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tslib_gifbuilder');
                                        $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'];
                                        $offset = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $JSwindowExpand . ',');
                                        $newWindow = isset($conf['JSwindow.']['newWindow.']) ? $this->stdWrap($conf['JSwindow.']['newWindow'], $conf['JSwindow.']['newWindow.']) : $conf['JSwindow.']['newWindow'];
@@ -5105,7 +5105,7 @@ class ContentObjectRenderer {
                        $gifCreator = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('tslib_gifbuilder');
                        /** @var $gifCreator tslib_gifbuilder */
                        $gifCreator->init();
-                       $info = $gifCreator->imageMagickConvert($theImage, 'WEB', '', '', '', '', '');
+                       $info = $gifCreator->imageMagickConvert($theImage, 'WEB');
                        $info['origFile'] = $theImage;
                        // This is needed by tslib_gifbuilder, ln 100ff in order for the setup-array to create a unique filename hash.
                        $info['origFile_mtime'] = @filemtime($theImage);
index 6e44c08..c1bffa2 100644 (file)
@@ -146,7 +146,7 @@ class ShowImageController {
                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 = '';
                $this->content .= '
index 453cdf6..0c55f35 100644 (file)
@@ -4035,7 +4035,7 @@ REMOTE_ADDR was \'' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE
                                                        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]);
                                        }
@@ -4047,7 +4047,7 @@ REMOTE_ADDR was \'' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE
                                                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]);
                                }
@@ -4058,7 +4058,7 @@ REMOTE_ADDR was \'' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE
                                                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]);
                                }
@@ -4095,7 +4095,7 @@ REMOTE_ADDR was \'' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE
                                        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 = \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize(@filesize($fileInfo[3]));
@@ -4112,7 +4112,7 @@ REMOTE_ADDR was \'' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE
                                $imageProc->IM_commands = array();
                                $theFile = \TYPO3\CMS\Core\Extension\ExtensionManager::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 {
@@ -4145,7 +4145,7 @@ REMOTE_ADDR was \'' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE
                                        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 = \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize(@filesize($fileInfo[3]));
@@ -4164,7 +4164,7 @@ REMOTE_ADDR was \'' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE
                                        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]);
                                $imageProc->IM_commands = array();
@@ -4173,7 +4173,7 @@ REMOTE_ADDR was \'' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REMOTE
                                        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 {