From 278227608808c25242c87a7092da5fb9adc50cde Mon Sep 17 00:00:00 2001 From: =?utf8?q?M=C3=A1t=C3=A9=20Szab=C3=B3?= Date: Mon, 16 Sep 2019 21:30:47 +0200 Subject: [PATCH] SectionProfiler: Do not attempt to use null values as arrays When SectionProfiler::getFunctionStats() is called, the 'start' and 'end' member variables may be null if no code called the scopedProfileIn()/scopedProfileOut() methods on this profiler instance. This can occur, for instance, when generating the parser limit report for wikitext that did not include expensive parser functions. In PHP 7.4, attemping to use a null value as an array generates a PHP Notice.[1] This patch adds a check to SectionProfiler::getFunctionStats to verify that the 'start' value is an array before attempting to access its keys. --- [1] https://github.com/php/php-src/blob/php-7.4.0RC1/UPGRADING#L25 Bug: T233012 Change-Id: I2d35bfddfcc4c194aa71265e40387f2f2914e3a5 --- includes/profiler/SectionProfiler.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/includes/profiler/SectionProfiler.php b/includes/profiler/SectionProfiler.php index c27ab4f3f4..92e276d766 100644 --- a/includes/profiler/SectionProfiler.php +++ b/includes/profiler/SectionProfiler.php @@ -96,9 +96,15 @@ class SectionProfiler { public function getFunctionStats() { $this->collateData(); - $totalCpu = max( $this->end['cpu'] - $this->start['cpu'], 0 ); - $totalReal = max( $this->end['real'] - $this->start['real'], 0 ); - $totalMem = max( $this->end['memory'] - $this->start['memory'], 0 ); + if ( is_array( $this->start ) ) { + $totalCpu = max( $this->end['cpu'] - $this->start['cpu'], 0 ); + $totalReal = max( $this->end['real'] - $this->start['real'], 0 ); + $totalMem = max( $this->end['memory'] - $this->start['memory'], 0 ); + } else { + $totalCpu = 0; + $totalReal = 0; + $totalMem = 0; + } $profile = []; foreach ( $this->collated as $fname => $data ) { -- 2.20.1