Don't try to call load() on non-object
authorFlorian <florian.schmidt.stargatewissen@gmail.com>
Fri, 10 Jul 2015 14:31:33 +0000 (16:31 +0200)
committerFlorian <florian.schmidt.stargatewissen@gmail.com>
Fri, 10 Jul 2015 18:35:02 +0000 (20:35 +0200)
FileRepo::newFile() can return null or false, in addition to a File
object. Calling load() on the returned value in FileRepo::findFile()
can result in an exception. Prevent this with an additional check after
FileRepo::newFile() was called.

Follow up: I1aa4b096c0cad5f5ca34321cc897019005c53a76
Follow up: I60c106b5b27db067b1884af95f5fb74a0a682a9a

Bug: T105497
Change-Id: Iabdae8fd960d19a467dc08a193228978575017ce

includes/filerepo/FileRepo.php

index 5bac289..82bbd76 100644 (file)
@@ -433,16 +433,16 @@ class FileRepo {
                        $img = $this->newFile( $title, $time );
                        if ( $img ) {
                                $img->load( $flags );
-                       }
-                       if ( $img && $img->exists() ) {
-                               if ( !$img->isDeleted( File::DELETED_FILE ) ) {
-                                       return $img; // always OK
-                               } elseif ( !empty( $options['private'] ) &&
-                                       $img->userCan( File::DELETED_FILE,
-                                               $options['private'] instanceof User ? $options['private'] : null
-                                       )
-                               ) {
-                                       return $img;
+                               if ( $img->exists() ) {
+                                       if ( !$img->isDeleted( File::DELETED_FILE ) ) {
+                                               return $img; // always OK
+                                       } elseif ( !empty( $options['private'] ) &&
+                                               $img->userCan( File::DELETED_FILE,
+                                                       $options['private'] instanceof User ? $options['private'] : null
+                                               )
+                                       ) {
+                                               return $img;
+                                       }
                                }
                        }
                }