From ade48c2cb12d608edd7c64ab07eb9b4172b08517 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 26 May 2019 12:13:54 -0500 Subject: [PATCH 1/2] Tests/BigInteger: GMP engine didn't always return 1 or -1 --- tests/Unit/Math/BigInteger/TestCase.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Unit/Math/BigInteger/TestCase.php b/tests/Unit/Math/BigInteger/TestCase.php index 821e4280..103b5c6a 100644 --- a/tests/Unit/Math/BigInteger/TestCase.php +++ b/tests/Unit/Math/BigInteger/TestCase.php @@ -185,6 +185,9 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase // c < d $this->assertLessThan(0, $c->compare($d)); $this->assertGreaterThan(0, $d->compare($c)); + + $this->assertSame(-1, $this->getInstance(-999)->compare($this->getInstance(370))); + $this->assertSame(1, $this->getInstance(999)->compare($this->getInstance(-700))); } public function testBitwiseAND() From 8b76e96b833b68430f07da2f0f807d9aee023561 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sun, 26 May 2019 12:14:44 -0500 Subject: [PATCH 2/2] BigInteger: GMP engine didn't always return 1 or -1 --- phpseclib/Math/BigInteger.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index da79b031..1807e4aa 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -2727,7 +2727,14 @@ class Math_BigInteger { switch (MATH_BIGINTEGER_MODE) { case MATH_BIGINTEGER_MODE_GMP: - return gmp_cmp($this->value, $y->value); + $r = gmp_cmp($this->value, $y->value); + if ($r < -1) { + $r = -1; + } + if ($r > 1) { + $r = 1; + } + return $r; case MATH_BIGINTEGER_MODE_BCMATH: return bccomp($this->value, $y->value, 0); }