Guard against uncountable tag values
authorSam Wilson <sam@samwilson.id.au>
Sat, 30 Jun 2018 07:55:47 +0000 (15:55 +0800)
committerPaladox <thomasmulhall410@yahoo.com>
Wed, 1 Aug 2018 19:41:57 +0000 (19:41 +0000)
As of PHP 7.2 counting false or null raises a "Warning: count(): Parameter must be an array or an object that implements Countable".

Bug: T182377
Bug: T196793
Change-Id: I7ca38bc55ae04f68106fe0d27c7d496da1538459
(cherry picked from commit 61af022e5f8e06c2588a8fc3fd003f52bdb85b08)

RELEASE-NOTES-1.31
includes/media/Exif.php

index 4841f77..cf10354 100644 (file)
@@ -15,6 +15,7 @@ This is a security and maintenance release of the MediaWiki 1.31 branch.
 * (T151415) Log email changes.
 * (T197206) Fix performance regression when multiple DB used without caching.
 * (T197030) PHPSessionHandler: Suppress headers warnings in initialize().
 * (T151415) Log email changes.
 * (T197206) Fix performance regression when multiple DB used without caching.
 * (T197030) PHPSessionHandler: Suppress headers warnings in initialize().
+* (T182377, T196793) Exif: Guard against uncountable tag values.
 
 === Changes since MediaWiki 1.31.0-rc.2 ===
 * (T195783) Initialize PSR-4 namespaces at same stage as normal autoloader.
 
 === Changes since MediaWiki 1.31.0-rc.2 ===
 * (T195783) Initialize PSR-4 namespaces at same stage as normal autoloader.
index a38e79b..70f8d5c 100644 (file)
@@ -742,12 +742,16 @@ class Exif {
                                $ecount = 1; // checking individual elements
                        }
                }
                                $ecount = 1; // checking individual elements
                        }
                }
-               $count = count( $val );
-               if ( $ecount != $count ) {
-                       $this->debug( $val, __FUNCTION__, "Expected $ecount elements for $tag but got $count" );
 
 
-                       return false;
+               $count = 1;
+               if ( is_array( $val ) ) {
+                       $count = count( $val );
+                       if ( $ecount != $count ) {
+                               $this->debug( $val, __FUNCTION__, "Expected $ecount elements for $tag but got $count" );
+                               return false;
+                       }
                }
                }
+               // If there are multiple values, recursively validate each of them.
                if ( $count > 1 ) {
                        foreach ( $val as $v ) {
                                if ( !$this->validate( $section, $tag, $v, true ) ) {
                if ( $count > 1 ) {
                        foreach ( $val as $v ) {
                                if ( !$this->validate( $section, $tag, $v, true ) ) {