[BUGFIX] Add check if $fileObject is a correct instance 12/33612/2
authorFrank Nägler <typo3@naegler.net>
Wed, 10 Sep 2014 19:55:21 +0000 (21:55 +0200)
committerMarkus Klein <klein.t3@reelworx.at>
Wed, 29 Oct 2014 23:42:52 +0000 (00:42 +0100)
In some cases the $fileObject is null and getName() is called on
a null object which results in a fatal error.

This patch add a check if $fileObject is an instance of
FileInterface before call getName().
Also correct the wrong doc comment.

Resolves: #60773
Releases: 6.2, master
Change-Id: I6f3f817a089c665d8cc9e0b3369d6d690ffaf620
Reviewed-on: http://review.typo3.org/33612
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/core/Classes/Resource/ResourceFactory.php
typo3/sysext/core/Classes/Resource/ResourceStorage.php

index 9bd8acd..f5413d1 100644 (file)
@@ -395,7 +395,7 @@ class ResourceFactory implements ResourceFactoryInterface, \TYPO3\CMS\Core\Singl
         *
         * @param int $storageUid
         * @param string $fileIdentifier
-        * @return File|ProcessedFile
+        * @return NULL|File|ProcessedFile
         */
        public function getFileObjectByStorageAndIdentifier($storageUid, &$fileIdentifier) {
                $storage = $this->getStorageObject($storageUid, array(), $fileIdentifier);
@@ -642,4 +642,4 @@ class ResourceFactory implements ResourceFactoryInterface, \TYPO3\CMS\Core\Singl
                return GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Index\\Indexer', $storage);
        }
 
-}
\ No newline at end of file
+}
index 4058ed4..ee4e876 100644 (file)
@@ -1373,11 +1373,13 @@ class ResourceStorage implements ResourceStorageInterface {
                        } else {
                                $fileObject = $this->getFileFactory()->getFileObjectByStorageAndIdentifier($this->getUid(), $identifier);
                        }
-                       $key = $fileObject->getName();
-                       while (isset($items[$key])) {
-                               $key .= 'z';
+                       if ($fileObject instanceof FileInterface) {
+                               $key = $fileObject->getName();
+                               while (isset($items[$key])) {
+                                       $key .= 'z';
+                               }
+                               $items[$key] = $fileObject;
                        }
-                       $items[$key] = $fileObject;
                }
                uksort($items, 'strnatcasecmp');