com php-src: Avoid overflow in mul range calculation: ext/opcache/Optimizer/zend_inference.c
| From: | Nikita Popov | Date: | Thu, 20 Jun 2019 07:57:55 +0000 |
| Subject: | com php-src: Avoid overflow in mul range calculation: ext/opcache/Optimizer/zend_inference.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-106927@lists.php.net to get a copy of this message | ||
Commit: 117c7b3f65c6e884f14e1e71cda340a3becbed48
Author: Nikita Popov <nikita.ppv@gmail.com> Thu, 20 Jun 2019 09:57:55 +0200
Parents: 3a97b8b4f9f8ab20e9e62b9f63f95d167e308c20
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=117c7b3f65c6e884f14e1e71cda340a3becbed48
Log:
Avoid overflow in mul range calculation
By using ZEND_SIGNED_MULTIPLY_LONG, which already implemented
efficient overflow checking logic.
Changed paths:
M ext/opcache/Optimizer/zend_inference.c
Diff:
diff --git a/ext/opcache/Optimizer/zend_inference.c b/ext/opcache/Optimizer/zend_inference.c
index e969cba..e032005 100644
--- a/ext/opcache/Optimizer/zend_inference.c
+++ b/ext/opcache/Optimizer/zend_inference.c
@@ -621,23 +621,23 @@ static int zend_inference_calc_binary_op_range(
break;
case ZEND_MUL:
if (OP1_HAS_RANGE() && OP2_HAS_RANGE()) {
+ double dummy;
+ zend_long t1_overflow, t2_overflow, t3_overflow, t4_overflow;
op1_min = OP1_MIN_RANGE();
op2_min = OP2_MIN_RANGE();
op1_max = OP1_MAX_RANGE();
op2_max = OP2_MAX_RANGE();
- t1 = op1_min * op2_min;
- t2 = op1_min * op2_max;
- t3 = op1_max * op2_min;
- t4 = op1_max * op2_max;
+ ZEND_SIGNED_MULTIPLY_LONG(op1_min, op2_min, t1, dummy, t1_overflow);
+ ZEND_SIGNED_MULTIPLY_LONG(op1_min, op2_max, t2, dummy, t2_overflow);
+ ZEND_SIGNED_MULTIPLY_LONG(op1_max, op2_min, t3, dummy, t3_overflow);
+ ZEND_SIGNED_MULTIPLY_LONG(op1_max, op2_max, t4, dummy, t4_overflow);
+ (void) dummy;
+
// FIXME: more careful overflow checks?
- if (OP1_RANGE_UNDERFLOW() ||
- OP2_RANGE_UNDERFLOW() ||
- OP1_RANGE_OVERFLOW() ||
- OP2_RANGE_OVERFLOW() ||
- (double)t1 != (double)op1_min * (double)op2_min ||
- (double)t2 != (double)op1_min * (double)op2_max ||
- (double)t3 != (double)op1_max * (double)op2_min ||
- (double)t4 != (double)op1_max * (double)op2_max) {
+ if (OP1_RANGE_UNDERFLOW() || OP2_RANGE_UNDERFLOW() ||
+ OP1_RANGE_OVERFLOW() || OP2_RANGE_OVERFLOW() ||
+ t1_overflow || t2_overflow || t3_overflow || t4_overflow
+ ) {
tmp->underflow = 1;
tmp->overflow = 1;
tmp->min = ZEND_LONG_MIN;