Skip to content

Commit 756aaaf

Browse files
committed
Merge branch 'PHP-7.2'
* PHP-7.2: Fixed bug #75018, fixed bug #75177
2 parents 1edc5ae + b134793 commit 756aaaf

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

ext/mysqli/tests/bug75018.phpt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
Bug #75018 Data corruption when reading fields of bit type
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
require_once('skipifconnectfailure.inc');
7+
?>
8+
--FILE--
9+
<?php
10+
require_once("connect.inc");
11+
12+
$mysqli = new mysqli("$host:$port", $user, $passwd, $db);
13+
14+
$tbl = "test_bug75018";
15+
$sql = "DROP TABLE IF EXISTS $tbl";
16+
$mysqli->query($sql);
17+
18+
$sql = "CREATE TABLE $tbl (bit_column_1 bit(16) NOT NULL) DEFAULT CHARSET=utf8";
19+
$mysqli->query($sql);
20+
21+
$sql = "INSERT INTO $tbl (bit_column_1) VALUES (0)";
22+
$mysqli->query($sql);
23+
$sql = "INSERT INTO $tbl (bit_column_1) VALUES (0b10101010101)";
24+
$mysqli->query($sql);
25+
26+
$sql = "SELECT bit_column_1 FROM $tbl";
27+
$result = $mysqli->query($sql);
28+
29+
while ($row = $result->fetch_assoc()) {
30+
var_dump($row['bit_column_1']);
31+
}
32+
33+
?>
34+
==DONE==
35+
--EXPECT--
36+
string(1) "0"
37+
string(4) "1365"
38+
==DONE==

ext/mysqlnd/mysqlnd_wireprotocol.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ php_mysqlnd_rowp_read_text_protocol_aux(MYSQLND_MEMORY_POOL_CHUNK * row_buffer,
17611761
if (Z_TYPE_P(current_field) == IS_LONG && !as_int_or_float) {
17621762
/* we are using the text protocol, so convert to string */
17631763
char tmp[22];
1764-
const size_t tmp_len = sprintf((char *)&tmp, MYSQLND_LLU_SPEC, Z_LVAL_P(current_field));
1764+
const size_t tmp_len = sprintf((char *)&tmp, MYSQLND_LLU_SPEC, (uint64_t) Z_LVAL_P(current_field));
17651765
ZVAL_STRINGL(current_field, tmp, tmp_len);
17661766
} else if (Z_TYPE_P(current_field) == IS_STRING) {
17671767
/* nothing to do here, as we want a string and ps_fetch_from_1_to_8_bytes() has given us one */

ext/pdo_mysql/tests/bug75177.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
PDO MySQL Bug #75177 Type 'bit' is fetched as unexpected string
3+
--SKIPIF--
4+
<?php
5+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
6+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7+
MySQLPDOTest::skip();
8+
?>
9+
--FILE--
10+
<?php
11+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
12+
$pdo = MySQLPDOTest::factory();
13+
14+
$tbl = "tbl_bug75177";
15+
$pdo->query("DROP TABLE IF EXISTS $tbl");
16+
$pdo->query("CREATE TABLE $tbl (`bit` bit(8)) ENGINE=InnoDB");
17+
$pdo->query("INSERT INTO $tbl (`bit`) VALUES (1)");
18+
$pdo->query("INSERT INTO $tbl (`bit`) VALUES (0b011)");
19+
$pdo->query("INSERT INTO $tbl (`bit`) VALUES (0b01100)");
20+
21+
$ret = $pdo->query("SELECT * FROM $tbl")->fetchAll();
22+
23+
foreach ($ret as $i) {
24+
var_dump($i["bit"]);
25+
}
26+
27+
?>
28+
==DONE==
29+
--EXPECT--
30+
string(1) "1"
31+
string(1) "3"
32+
string(2) "12"
33+
==DONE==

0 commit comments

Comments
 (0)