From 56785a85dbf35fb7274bf62f5d8a90705a3d7be1 Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Sat, 17 Jan 2026 14:47:24 +0530 Subject: [PATCH 1/3] ext/gmp: fix bug16502 test expected error message --- ext/gmp/gmp.c | 8 ++++++++ ext/gmp/tests/bug16502.phpt | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 ext/gmp/tests/bug16502.phpt diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index b5451b8035e37..f2746a6e500de 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -372,6 +372,14 @@ static zend_result shift_operator_helper(gmp_binary_ui_op_t op, zval *return_val goto typeof_op_failure; } + if (shift > INT_MAX && opcode == ZEND_POW) { + zend_throw_error( + zend_ce_value_error, "Exponent must be less than %d", + INT_MAX + ); + ZVAL_UNDEF(return_value); + return FAILURE; + } INIT_GMP_RETVAL(gmpnum_result); op(gmpnum_result, gmpnum_op, (gmp_ulong) shift); return SUCCESS; diff --git a/ext/gmp/tests/bug16502.phpt b/ext/gmp/tests/bug16502.phpt new file mode 100644 index 0000000000000..965405cff5256 --- /dev/null +++ b/ext/gmp/tests/bug16502.phpt @@ -0,0 +1,17 @@ +--TEST-- +pow() with GMP exponent too large should throw ValueError +--EXTENSIONS-- +gmp +--FILE-- +getMessage(), "\n"; +} +?> +--EXPECTREGEX-- +Exponent must be less than [0-9]+ \ No newline at end of file From 03397545804fbe00f1235bfe0608837e623baa61 Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Sat, 17 Jan 2026 15:50:23 +0530 Subject: [PATCH 2/3] ext/gmp: fix bug16502 test expected error message --- ext/gmp/gmp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index f2746a6e500de..dd8389bc0c57d 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -372,10 +372,10 @@ static zend_result shift_operator_helper(gmp_binary_ui_op_t op, zval *return_val goto typeof_op_failure; } - if (shift > INT_MAX && opcode == ZEND_POW) { + if (shift > SHRT_MAX && opcode == ZEND_POW) { zend_throw_error( zend_ce_value_error, "Exponent must be less than %d", - INT_MAX + SHRT_MAX ); ZVAL_UNDEF(return_value); return FAILURE; From bc67ae2d760183cc855013374b6cb786ba3d18d8 Mon Sep 17 00:00:00 2001 From: arshidkv12 Date: Sat, 17 Jan 2026 16:24:12 +0530 Subject: [PATCH 3/3] ext/gmp: fix bug16502 test expected error message --- ext/gmp/gmp.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ext/gmp/gmp.c b/ext/gmp/gmp.c index dd8389bc0c57d..e0b64e8dfed5c 100644 --- a/ext/gmp/gmp.c +++ b/ext/gmp/gmp.c @@ -372,10 +372,11 @@ static zend_result shift_operator_helper(gmp_binary_ui_op_t op, zval *return_val goto typeof_op_failure; } - if (shift > SHRT_MAX && opcode == ZEND_POW) { + if (shift > INT_MAX / 1000) { zend_throw_error( - zend_ce_value_error, "Exponent must be less than %d", - SHRT_MAX + zend_ce_value_error, "%s must be less than %d", + opcode == ZEND_POW ? "Exponent" : "Shift", + (INT_MAX / 1000) ); ZVAL_UNDEF(return_value); return FAILURE;