Skip to content

Commit 1a66d64

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fixed bug #67983
2 parents f6bd3df + 315f3f8 commit 1a66d64

File tree

3 files changed

+62
-22
lines changed

3 files changed

+62
-22
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ PHP NEWS
55
- Core:
66
. Fixed bug #80523 (bogus parse error on >4GB source code). (Nikita)
77

8+
- MySQLi:
9+
. Fixed bug #67983 (mysqlnd with MYSQLI_OPT_INT_AND_FLOAT_NATIVE fails to
10+
interpret bit columns). (Nikita)
11+
812
07 Jan 2021, PHP 8.0.1
913

1014
- Core:

ext/mysqli/tests/bug67983.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Bug #67983: mysqlnd with MYSQLI_OPT_INT_AND_FLOAT_NATIVE fails to interpret bit columns
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
require_once('skipifconnectfailure.inc');
7+
if (!$IS_MYSQLND) {
8+
die("skip mysqlnd only test");
9+
}
10+
?>
11+
--FILE--
12+
<?php
13+
14+
require_once("connect.inc");
15+
16+
$connection = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
17+
18+
mysqli_options($connection, MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true);
19+
20+
mysqli_set_charset($connection, 'utf8');
21+
mysqli_query($connection, 'DROP TABLE IF EXISTS test');
22+
mysqli_query($connection, 'CREATE TABLE test (id BIT(8))');
23+
mysqli_query($connection, 'INSERT INTO test VALUES (0), (1), (42)');
24+
25+
$res = mysqli_query($connection, 'SELECT * FROM test');
26+
27+
while ($result = mysqli_fetch_assoc($res)) {
28+
var_dump($result['id']);
29+
}
30+
31+
?>
32+
--EXPECT--
33+
int(0)
34+
int(1)
35+
int(42)

ext/mysqlnd/mysqlnd_wireprotocol.c

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,8 +1604,28 @@ php_mysqlnd_rowp_read_text_protocol_aux(MYSQLND_ROW_BUFFER * row_buffer, zval *
16041604
}
16051605
MYSQLND_INC_CONN_STATISTIC_W_VALUE2(stats, statistic, 1, STAT_BYTES_RECEIVED_PURE_DATA_TEXT, len);
16061606
}
1607+
if (fields_metadata[i].type == MYSQL_TYPE_BIT) {
1608+
/*
1609+
BIT fields are specially handled. As they come as bit mask, they have
1610+
to be converted to human-readable representation.
1611+
*/
1612+
ps_fetch_from_1_to_8_bytes(current_field, &(fields_metadata[i]), 0, (const zend_uchar **) &p, len);
1613+
/*
1614+
We have advanced in ps_fetch_from_1_to_8_bytes. We should go back because
1615+
later in this function there will be an advancement.
1616+
*/
1617+
p -= len;
1618+
if (Z_TYPE_P(current_field) == IS_LONG && !as_int_or_float) {
1619+
/* we are using the text protocol, so convert to string */
1620+
char tmp[22];
1621+
const size_t tmp_len = sprintf((char *)&tmp, ZEND_ULONG_FMT, Z_LVAL_P(current_field));
1622+
ZVAL_STRINGL(current_field, tmp, tmp_len);
1623+
} else if (Z_TYPE_P(current_field) == IS_STRING) {
1624+
/* nothing to do here, as we want a string and ps_fetch_from_1_to_8_bytes() has given us one */
1625+
}
1626+
}
16071627
#ifdef MYSQLND_STRING_TO_INT_CONVERSION
1608-
if (as_int_or_float && perm_bind.php_type == IS_LONG) {
1628+
else if (as_int_or_float && perm_bind.php_type == IS_LONG) {
16091629
zend_uchar save = *(p + len);
16101630
/* We have to make it ASCIIZ temporarily */
16111631
*(p + len) = '\0';
@@ -1649,28 +1669,9 @@ php_mysqlnd_rowp_read_text_protocol_aux(MYSQLND_ROW_BUFFER * row_buffer, zval *
16491669
*(p + len) = '\0';
16501670
ZVAL_DOUBLE(current_field, atof((char *) p));
16511671
*(p + len) = save;
1652-
} else
1672+
}
16531673
#endif /* MYSQLND_STRING_TO_INT_CONVERSION */
1654-
if (fields_metadata[i].type == MYSQL_TYPE_BIT) {
1655-
/*
1656-
BIT fields are specially handled. As they come as bit mask, they have
1657-
to be converted to human-readable representation.
1658-
*/
1659-
ps_fetch_from_1_to_8_bytes(current_field, &(fields_metadata[i]), 0, (const zend_uchar **) &p, len);
1660-
/*
1661-
We have advanced in ps_fetch_from_1_to_8_bytes. We should go back because
1662-
later in this function there will be an advancement.
1663-
*/
1664-
p -= len;
1665-
if (Z_TYPE_P(current_field) == IS_LONG && !as_int_or_float) {
1666-
/* we are using the text protocol, so convert to string */
1667-
char tmp[22];
1668-
const size_t tmp_len = sprintf((char *)&tmp, ZEND_ULONG_FMT, Z_LVAL_P(current_field));
1669-
ZVAL_STRINGL(current_field, tmp, tmp_len);
1670-
} else if (Z_TYPE_P(current_field) == IS_STRING) {
1671-
/* nothing to do here, as we want a string and ps_fetch_from_1_to_8_bytes() has given us one */
1672-
}
1673-
} else {
1674+
else {
16741675
ZVAL_STRINGL_FAST(current_field, (char *)p, len);
16751676
}
16761677
p += len;

0 commit comments

Comments
 (0)