From 61af022e5f8e06c2588a8fc3fd003f52bdb85b08 Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Sat, 30 Jun 2018 15:55:47 +0800 Subject: [PATCH] Guard against uncountable tag values 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 --- includes/media/Exif.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/includes/media/Exif.php b/includes/media/Exif.php index e4de0a1b5f..9977f45abd 100644 --- a/includes/media/Exif.php +++ b/includes/media/Exif.php @@ -742,12 +742,16 @@ class Exif { $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 ) ) { -- 2.20.1