From 8de7a893c2574f1a9016c85b1a43c05e5e923c5f Mon Sep 17 00:00:00 2001 From: terrafrost Date: Fri, 29 Nov 2024 00:35:25 -0600 Subject: [PATCH] BigInteger: improve detection of newly introduced GMP bug --- phpseclib/Math/BigInteger.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index 066788ad..439c3663 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -245,9 +245,17 @@ class Math_BigInteger function __construct($x = 0, $base = 10) { if (!defined('MATH_BIGINTEGER_MODE')) { + + // https://github.com/php/php-src/commit/e0a0e216a909dc4ee4ea7c113a5f41d49525f02e broke GMP + // https://github.com/php/php-src/commit/424ba0f2ff9677d16b4e339e90885bd4bc49fcf1 fixed it + // see https://github.com/php/php-src/issues/16870 for more info + if (version_compare(PHP_VERSION, '8.2.26', '<')) { + $gmpOK = true; + } else { + $gmpOK = !in_array(PHP_VERSION_ID, array(80226, 80314, 80400, 80401)); + } switch (true) { - // PHP 8.4.0 and 8.4.1 don't work with GMP per https://github.com/php/php-src/issues/16870 - case extension_loaded('gmp') && !(version_compare(PHP_VERSION, '8.4.0', '>=') && version_compare(PHP_VERSION, '8.4.1', '<=')): + case extension_loaded('gmp') && $gmpOK: define('MATH_BIGINTEGER_MODE', MATH_BIGINTEGER_MODE_GMP); break; case extension_loaded('bcmath'):