[BUGFIX] meaningfulTempFilePrefix is not multi-byte safe
authorSteffen Gebert <steffen.gebert@typo3.org>
Sun, 2 Oct 2011 08:23:59 +0000 (10:23 +0200)
committerJigal van Hemert <jigal@xs4all.nl>
Tue, 4 Oct 2011 20:49:55 +0000 (22:49 +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: I760f80b8cfa2dcea8b554c24467f56b662d465d9
Resolves: #30416
Releases: 4.5, 4.6
Author: Steffen Gebert <steffen.gebert@typo3.org>
Reviewed-on: http://review.typo3.org/5479
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
typo3/sysext/cms/tslib/class.tslib_content.php
typo3/sysext/cms/tslib/class.tslib_gifbuilder.php

index ad35714..10d2327 100644 (file)
@@ -4963,9 +4963,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 1c87d82..f650952 100644 (file)
@@ -711,8 +711,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) {
@@ -725,7 +725,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.