Skip to content

Commit 56785a8

Browse files
committed
ext/gmp: fix bug16502 test expected error message
1 parent 084e409 commit 56785a8

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

ext/gmp/gmp.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,14 @@ static zend_result shift_operator_helper(gmp_binary_ui_op_t op, zval *return_val
372372
goto typeof_op_failure;
373373
}
374374

375+
if (shift > INT_MAX && opcode == ZEND_POW) {
376+
zend_throw_error(
377+
zend_ce_value_error, "Exponent must be less than %d",
378+
INT_MAX
379+
);
380+
ZVAL_UNDEF(return_value);
381+
return FAILURE;
382+
}
375383
INIT_GMP_RETVAL(gmpnum_result);
376384
op(gmpnum_result, gmpnum_op, (gmp_ulong) shift);
377385
return SUCCESS;

ext/gmp/tests/bug16502.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
pow() with GMP exponent too large should throw ValueError
3+
--EXTENSIONS--
4+
gmp
5+
--FILE--
6+
<?php
7+
$a = gmp_init(10000000000);
8+
9+
try {
10+
pow($a, $a);
11+
echo "NO_EXCEPTION\n";
12+
} catch (ValueError $e) {
13+
echo $e->getMessage(), "\n";
14+
}
15+
?>
16+
--EXPECTREGEX--
17+
Exponent must be less than [0-9]+

0 commit comments

Comments
 (0)