Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions ext/gmp/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,15 @@ static zend_result shift_operator_helper(gmp_binary_ui_op_t op, zval *return_val
goto typeof_op_failure;
}

if (shift > INT_MAX / 1000) {
zend_throw_error(
zend_ce_value_error, "%s must be less than %d",
opcode == ZEND_POW ? "Exponent" : "Shift",
(INT_MAX / 1000)
);
ZVAL_UNDEF(return_value);
return FAILURE;
}
INIT_GMP_RETVAL(gmpnum_result);
op(gmpnum_result, gmpnum_op, (gmp_ulong) shift);
return SUCCESS;
Expand Down
17 changes: 17 additions & 0 deletions ext/gmp/tests/bug16502.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
pow() with GMP exponent too large should throw ValueError
--EXTENSIONS--
gmp
--FILE--
<?php
$a = gmp_init(10000000000);

try {
pow($a, $a);
echo "NO_EXCEPTION\n";
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECTREGEX--
Exponent must be less than [0-9]+
Loading