From 4fb5088f86d2b62d4bdf1291624116ea3152660a Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Wed, 9 Oct 2013 10:06:47 -0400 Subject: [PATCH] bug #3678 Does not display or manipulate bit(64) fields appropriately --- ChangeLog | 1 + libraries/Util.class.php | 30 ++++++++++++++++--- .../common/PMA_printableBitValue_test.php | 4 +-- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2ab159c03..a88a664e7c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ phpMyAdmin - ChangeLog - bug #4108 Missing refresh by deleting databases - bug #3995 Drizzle server charset notice - bug #3911 Filtering database names includes empty groupings +- bug #3678 Does not display or manipulate bit(64) fields appropriately 4.0.8.0 (2013-10-06) - bug #3988 Rename view is not working diff --git a/libraries/Util.class.php b/libraries/Util.class.php index 1abe8717b2..c6bc407dca 100644 --- a/libraries/Util.class.php +++ b/libraries/Util.class.php @@ -3000,6 +3000,7 @@ class PMA_Util * Converts a bit value to printable format; * in MySQL a BIT field can be from 1 to 64 bits so we need this * function because in PHP, decbin() supports only 32 bits + * on 32-bit servers * * @param numeric $value coming from a BIT field * @param integer $length length @@ -3008,11 +3009,32 @@ class PMA_Util */ public static function printableBitValue($value, $length) { - $printable = ''; - for ($i = 0, $len_ceiled = ceil($length / 8); $i < $len_ceiled; $i++) { - $printable .= sprintf('%08d', decbin(ord(substr($value, $i, 1)))); + // if running on a 64-bit server or the length is safe for decbin() + if (PHP_INT_SIZE == 8 || $length < 33) { + $printable = decbin($value); + } else { + // FIXME: does not work for the leftmost bit of a 64-bit value + $i = 0; + $printable = ''; + while ($value >= pow(2, $i)) { + $i++; + } + if ($i != 0) { + $i = $i - 1; + } + + while ($i >= 0) { + if ($value - pow(2, $i) < 0) { + $printable = '0' . $printable; + } else { + $printable = '1' . $printable; + $value = $value - pow(2, $i); + } + $i--; + } + $printable = strrev($printable); } - $printable = substr($printable, -$length); + $printable = str_pad($printable, $length, '0', STR_PAD_LEFT); return $printable; } diff --git a/test/libraries/common/PMA_printableBitValue_test.php b/test/libraries/common/PMA_printableBitValue_test.php index 2a63d870dd..bce63f5751 100644 --- a/test/libraries/common/PMA_printableBitValue_test.php +++ b/test/libraries/common/PMA_printableBitValue_test.php @@ -23,8 +23,8 @@ class PMA_PrintableBitValueTest extends PHPUnit_Framework_TestCase public function printableBitValueDataProvider() { return array( - array('testtest', 64, '0111010001100101011100110111010001110100011001010111001101110100'), - array('test', 32, '01110100011001010111001101110100') + array('20131009', 64, '0000000000000000000000000000000000000001001100110010110011000001'), + array('5', 32, '00000000000000000000000000000101') ); }