Always evaluate the offset when retrieving array elements

Even if the array is DUNDEFINED, we need to check the offset to ensure
that it's valid.

Bug: T237351
Change-Id: Ibfa360c4ae1d80abe14d9fdf66991b76cb5954df
This commit is contained in:
Daimona Eaytoy 2019-11-06 10:09:56 +01:00
parent cb6f3500b1
commit 8ad4ecd31d
2 changed files with 5 additions and 2 deletions

View file

@ -171,6 +171,9 @@ class AbuseFilterCachingParser extends AbuseFilterParser {
list( $array, $offset ) = $node->children;
$array = $this->evalNode( $array );
// Note: we MUST evaluate the offset to ensure it is valid, regardless
// of $array!
$offset = $this->evalNode( $offset )->toInt();
if ( $array->getType() === AFPData::DUNDEFINED ) {
return new AFPData( AFPData::DUNDEFINED );
@ -180,8 +183,6 @@ class AbuseFilterCachingParser extends AbuseFilterParser {
throw new AFPUserVisibleException( 'notarray', $node->position, [] );
}
$offset = $this->evalNode( $offset )->toInt();
$array = $array->toArray();
if ( count( $array ) <= $offset ) {
throw new AFPUserVisibleException( 'outofbounds', $node->position,

View file

@ -301,6 +301,8 @@ class AbuseFilterParserTest extends AbuseFilterParserTestCase {
[ 'a[1] := 5', 'getVarValue' ],
[ 'a[] := 5', 'getVarValue' ],
[ 'a = 5', 'getVarValue' ],
[ 'timestamp[a]', 'getVarValue' ],
[ 'x := []; x[a] := 1', 'getVarValue' ],
];
}