parser: Validate $length in padleft/padright parser functions
authorKunal Mehta <legoktm@member.fsf.org>
Sun, 10 Jun 2018 18:09:07 +0000 (11:09 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Sun, 10 Jun 2018 18:20:13 +0000 (11:20 -0700)
commitdc96f656affd1f8fab0ae72b0d96e77055e5b336
tree274ad34aecae68e44203ff4054b06158839b1d03
parentd62d7eff494c225b21c12242bc5bedcffc9f306d
parser: Validate $length in padleft/padright parser functions

$length is user input, so cast it to an int before passing it to min().
If there is nothing to add at that point, return immediately.

In PHP 7.1+ this raised a warning of "A non-numeric value encountered"
because min() will return the junk value, returning a string. Then we
try and subtract an int from it (return value of mb_strlen()),
triggering the warning.

Added a parser test to verify the behavior, and confirmed that it
triggers warnings without the patch.

Bug: T180403
Change-Id: I614750962104f6251a864519035366ac9798fc0f
includes/parser/CoreParserFunctions.php
tests/parser/parserTests.txt