From 48e50fe8fa32f4be4e9a8e1f6cdc30c75b40413c Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 9 Apr 2018 23:36:36 -0500 Subject: [PATCH 1/2] Tests/BigInteger: add test for conversion of 48 to signed hex --- tests/Unit/Math/BigInteger/TestCase.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Unit/Math/BigInteger/TestCase.php b/tests/Unit/Math/BigInteger/TestCase.php index 3338aadb..e7f7bbeb 100644 --- a/tests/Unit/Math/BigInteger/TestCase.php +++ b/tests/Unit/Math/BigInteger/TestCase.php @@ -397,4 +397,13 @@ abstract class Unit_Math_BigInteger_TestCase extends PhpseclibTestCase $n = $this->getInstance(2); $x->powMod($e, $n); } + + /** + * @group github1264 + */ + public function test48ToHex() + { + $temp = $this->getInstance(48); + $this->assertSame($temp->toHex(true), '30'); + } } From c63c2239726754249f025dc022f23ab76c70df9a Mon Sep 17 00:00:00 2001 From: terrafrost Date: Mon, 9 Apr 2018 23:47:38 -0500 Subject: [PATCH 2/2] BigInteger: fix for (new BigInteger(48))->toString(true) --- phpseclib/Math/BigInteger.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/Math/BigInteger.php b/phpseclib/Math/BigInteger.php index 969c9ad6..32afa7a0 100644 --- a/phpseclib/Math/BigInteger.php +++ b/phpseclib/Math/BigInteger.php @@ -550,7 +550,7 @@ class Math_BigInteger $temp = $comparison < 0 ? $this->add(new Math_BigInteger(1)) : $this->copy(); $bytes = $temp->toBytes(); - if (empty($bytes)) { // eg. if the number we're trying to convert is -1 + if (!strlen($bytes)) { // eg. if the number we're trying to convert is -1 $bytes = chr(0); }