[php-src] PR #12755: Fix range inference for UNDEF|NULL operands
| From: | iluuu1994 | Date: | Thu, 23 Nov 2023 01:41:26 +0000 |
| Subject: | [php-src] PR #12755: Fix range inference for UNDEF|NULL operands | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-24290@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/12755
Author: iluuu1994
Fixes oss-fuzz #59114
Range analysis naively assumes that all operands are integer. This can however lead to incorrect
results for non-numeric operands. For example, a PI node resulting from
$a < -1 will
contain the [-..-2] range constraint. Since in PHP null < -1 evaluates to true, this
can lead to a cascading effect where $a + $a is inferred as [-..-4], whereas the actual
result may be 0.
This PR solves this by performing type inference before range inference. This means that we
pessimistically assume all arithmetic operations will over- or underflow, adding MAY_BE_DOUBLE. This
is fixed by a second pass after range analysis that repeats inference for the relevant opcodes.
Range analysis may now use the available type information to widen the range where necessary.
@dstogov This is just an idea. Please let me know whether you think it makes sense. This might also
be relevant for false/true, I'll verify tomorrow via tests, too tired
now. ^^