[BUGFIX] meaningfulTempFilePrefix is not multi-byte safe
authorSteffen Gebert <steffen.gebert@typo3.org>
Sun, 2 Oct 2011 08:23:59 +0000 (10:23 +0200)
committerSteffen Gebert <steffen.gebert@typo3.org>
Wed, 5 Oct 2011 17:43:21 +0000 (19:43 +0200)
On a utf-8 file system meaningful prefixes can contain utf-8 characters. To
prevent truncating in the middle of a multi-byte character the API functions
must be used instead of substr().

Change-Id: Icf1a0cd1c095402cd31768ac732ec9bc9dfe7519
Resolves: #30416
Releases: 4.5, 4.6
Reviewed-on: http://review.typo3.org/5572
Reviewed-by: Steffen Gebert
Tested-by: Steffen Gebert
typo3/sysext/cms/tslib/class.tslib_content.php
typo3/sysext/cms/tslib/class.tslib_gifbuilder.php

index a2714db..aef6401 100644 (file)
@@ -4988,9 +4988,17 @@ class tslib_cObj {
                                                                $filename = basename($theImage);
                                                                        // remove extension
                                                                $filename = substr($filename, 0, strrpos($filename, '.'));
-                                                                       // strip everything non-ascii
-                                                               $filename = preg_replace('/[^A-Za-z0-9_-]/', '', trim($filename));
-                                                               $gifCreator->filenamePrefix = substr($filename, 0, intval($GLOBALS['TSFE']->config['config']['meaningfulTempFilePrefix'])) . '_';
+                                                               $tempFilePrefixLength = intval($GLOBALS['TSFE']->config['config']['meaningfulTempFilePrefix']);
+                                                               if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) {
+                                                                               /** @var $t3libCsInstance t3lib_cs */
+                                                                       $t3libCsInstance = t3lib_div::makeInstance('t3lib_cs');
+                                                                       $filenamePrefix = $t3libCsInstance->substr('utf-8', $filename, 0, $tempFilePrefixLength);
+                                                               } else {
+                                                                               // strip everything non-ascii
+                                                                       $filename = preg_replace('/[^A-Za-z0-9_-]/', '', trim($filename));
+                                                                       $filenamePrefix = substr($filename, 0, $tempFilePrefixLength);
+                                                               }
+                                                               $gifCreator->filenamePrefix = $filenamePrefix . '_';
                                                                unset($filename);
                                                        }
 
index 61db43e..1296d78 100644 (file)
@@ -707,8 +707,8 @@ class tslib_gifBuilder extends t3lib_stdGraphic {
        /**
         * Calculates the GIFBUILDER output filename/path based on a serialized, hashed value of this->setup
         *
-        * @param       string          Filename prefix, eg. "GB_"
-        * @return      string          The relative filepath (relative to PATH_site)
+        * @param $pre string Filename prefix, eg. "GB_"
+        * @return string The relative filepath (relative to PATH_site)
         * @access private
         */
        function fileName($pre) {
@@ -721,7 +721,15 @@ class tslib_gifBuilder extends t3lib_stdGraphic {
                        
                        $meaningfulPrefix = implode('_', array_merge($this->combinedTextStrings, $this->combinedFileNames));
                        $meaningfulPrefix = $basicFileFunctions->cleanFileName($meaningfulPrefix);
-                       $meaningfulPrefix = substr($meaningfulPrefix, 0, intval($GLOBALS['TSFE']->config['config']['meaningfulTempFilePrefix'])) . '_';
+                       $meaningfulPrefixLength = intval($GLOBALS['TSFE']->config['config']['meaningfulTempFilePrefix']);
+                       if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['UTF8filesystem']) {
+                                       /** @var $t3libCsInstance t3lib_cs */
+                               $t3libCsInstance = t3lib_div::makeInstance('t3lib_cs');
+                               $meaningfulPrefix = $t3libCsInstance->substr('utf-8', $meaningfulPrefix, 0, $meaningfulPrefixLength);
+                       } else {
+                               $meaningfulPrefix = substr($meaningfulPrefix, 0, $meaningfulPrefixLength);
+                       }
+                       $meaningfulPrefix .= '_';
                }
 
                        // WARNING: In PHP5 I discovered that rendering with freetype of Japanese letters was totally corrupt. Not only the wrong glyphs are printed but also some memory stack overflow resulted in strange additional chars - and finally the reason for this investigation: The Bounding box data was changing all the time resulting in new images being generated all the time. With PHP4 it works fine.