Issue Bug Closed

#99998Trying to access array offset on value of type bool in typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php line 2180

Thomas Hohn 02/21/23, 09:02 updated 03/14/23, 11:47

Description

From time to time we see the following php warning in out logs. Tried to reproduce it which is very hard – since we have a big distributed env.

 Got error 'PHP message: TYPO3 [WARNING] request="8926f60c7cbed" component="TYPO3.CMS.Core.Type.File.ImageInfo": I could not retrieve the image size for file 
 SITENAME/web/typo3temp/assets/images/40dc6871ee0cefaf7e6fa10a81996d0c.png - 
 {"file":"SITENAME\\/web\\/typo3temp\\/assets\\/images\\/40dc6871ee0cefaf7e6fa10a81996d0c.png"}
 PHP message: TYPO3 [WARNING] request="8926f60c7cbed" component="TYPO3.CMS.Core.Error.ErrorHandler": Core: Error handler (FE): PHP Warning: Trying to access array offset on value of type bool in typo3/sysext/core/Classes/Imaging/GraphicalFunctions.php line 2180 
 PHP message: TYPO3 [WARNING] request="8926f60c7cbed" component="TYPO3.CMS.Core.Error.ErrorHandler": Core: Error handler (FE): PHP Warning: Trying to access array offset on value of type bool in typo3/sysext/core/Classes/Resource/Processing/LocalCropScaleMaskHelper.php line 194 
 PHP message: TYPO3 [WARNING] request="8926f60c7cbed" component="TYPO3.CMS.Core.Error.ErrorHandler": Core: Error handler (FE): PHP Warning: Trying to access array offset on value of type bool in typo3/sysext/core/Classes/Resource/Processing/LocalCropScaleMaskHelper.php line 196 
 PHP message: TYPO3 [WARNING] request="8926f60c7cbed" component="TYPO3.CMS.Core.Error.ErrorHandler": Core: Error handler (FE): PHP Warning: Trying to access array offset on value of type bool in typo3/sysext/core/Classes/Resource/Processing/LocalCropScaleMaskHelper.php line 197 
 PHP message: TYPO3 [WARNING] request="8926f60c7cbed" component="TYPO3.CMS.Core.Error.ErrorHandler": Core: Error handler (FE): PHP Warning: Trying to access array offset on value of type bool in typo3/sysext/core/Classes/Resource/Processing/LocalCropScaleMaskHelper.php line 198

We believe that it comes from a race condition in the following function

    public function getImageDimensions($imageFile)
    {
        $returnArr = null;
        preg_match('/([^\\.]*)$/', $imageFile, $reg);
        if (file_exists($imageFile) && in_array(strtolower($reg[0]), $this->imageFileExt, true)) {
            $returnArr = $this->getCachedImageDimensions($imageFile);
            if (!$returnArr) {
                $imageInfoObject = GeneralUtility::makeInstance(ImageInfo::class, $imageFile);
                if ($imageInfoObject->getWidth()) {
                    $returnArr = [
                        $imageInfoObject->getWidth(),
                        $imageInfoObject->getHeight(),
                        strtolower($reg[0]),
                        $imageFile,
                    ];
                    $this->cacheImageDimensions($returnArr);
                }
            }
        }
        return $returnArr;
    }

Where $this->getCachedImageDimensions($imageFile) returns false and the call to $imageInfoObject->getWidth()) yields 0 which leads to that the returnArr now contains a boolean with the value false, which results in an error in the LocalCropScaleMaskHelper class

Reviews 2