Florianschmidtwelzow has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/224083

Change subject: Don't try to call load() on non-object
......................................................................

Don't try to call load() on non-object

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.

Bug: T105497
Change-Id: Iabdae8fd960d19a467dc08a193228978575017ce
---
M includes/filerepo/FileRepo.php
1 file changed, 20 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/83/224083/1

diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php
index e66fdaf..3a3802e 100644
--- a/includes/filerepo/FileRepo.php
+++ b/includes/filerepo/FileRepo.php
@@ -431,16 +431,18 @@
                # Now try an old version of the file
                if ( $time !== false ) {
                        $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 && $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;
+                                       }
                                }
                        }
                }
@@ -452,14 +454,16 @@
                $redir = $this->checkRedirect( $title );
                if ( $redir && $title->getNamespace() == NS_FILE ) {
                        $img = $this->newFile( $redir );
-                       $img->load( $flags );
-                       if ( !$img ) {
-                               return false;
-                       }
-                       if ( $img->exists() ) {
-                               $img->redirectedFrom( $title->getDBkey() );
+                       if ( $img ) {
+                               $img->load( $flags );
+                               if ( !$img ) {
+                                       return false;
+                               }
+                               if ( $img->exists() ) {
+                                       $img->redirectedFrom( 
$title->getDBkey() );
 
-                               return $img;
+                                       return $img;
+                               }
                        }
                }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/224083
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iabdae8fd960d19a467dc08a193228978575017ce
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to