Skip to content

Commit 01c1afa

Browse files
andrewnesternikic
authored andcommitted
Fixed bug #74021
1 parent ee25eb0 commit 01c1afa

File tree

4 files changed

+60
-4
lines changed

4 files changed

+60
-4
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ PHP NEWS
2222
. Fixed bug #74031 (ReflectionFunction for imagepng is missing last two
2323
parameters). (finwe)
2424

25+
- Mysqlnd:
26+
. Fixed bug #74021 (fetch_array broken data. Data more then MEDIUMBLOB).
27+
(Andrew Nester, Nikita)
28+
2529
- Opcache:
2630
. Fixed bug #74019 (Segfault with list). (Laruence)
2731

ext/mysqli/tests/bug73800.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Bug #73800 (sporadic segfault with MYSQLI_OPT_INT_AND_FLOAT_NATIVE)
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
require_once('skipifconnectfailure.inc');
7+
if (PHP_INT_SIZE != 8) die('skip requires 64-bit');
8+
?>
9+
--FILE--
10+
<?php
11+
12+
require_once("connect.inc");
13+
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
14+
15+
$link->query('SET @@global.max_allowed_packet = 67108864');
16+
$link->close();
17+
18+
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
19+
$link->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, 1);
20+
21+
$res = $link->query("SELECT RPAD('1',9000000,'1') as a,RPAD('1',9000000,'1') as b, 9223372036854775807 as c");
22+
$r = $res->fetch_array();
23+
24+
var_dump($r['c']);
25+
?>
26+
--EXPECT--
27+
int(9223372036854775807)

ext/mysqli/tests/bug74021.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Bug #74021 (fetch_array broken data. Data more then MEDIUMBLOB)
3+
--SKIPIF--
4+
<?php
5+
require_once('skipif.inc');
6+
require_once('skipifconnectfailure.inc');
7+
?>
8+
--FILE--
9+
<?php
10+
11+
require_once("connect.inc");
12+
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
13+
14+
$link->query('SET @@global.max_allowed_packet = 67108864');
15+
$link->close();
16+
17+
$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
18+
$res = $link->query("SELECT RPAD('1',9000000,'1') as a,RPAD('1',9000000,'1') as b");
19+
$r = $res->fetch_array();
20+
var_dump(md5($r['a']));
21+
var_dump(md5($r['b']));
22+
?>
23+
--EXPECT--
24+
string(32) "42ca0fd16ab6b6d4b9d47dc0a4a8b12a"
25+
string(32) "42ca0fd16ab6b6d4b9d47dc0a4a8b12a"

ext/mysqlnd/mysqlnd_wireprotocol.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,7 +1458,7 @@ php_mysqlnd_read_row_ex(MYSQLND_CONN_DATA * conn, MYSQLND_MEMORY_POOL * result_s
14581458
zero-length byte, don't read the body, there is no such.
14591459
*/
14601460

1461-
*data_size = prealloc_more_bytes;
1461+
*data_size = 0;
14621462
while (1) {
14631463
if (FAIL == mysqlnd_read_header(conn->net, &header, conn->stats, conn->error_info)) {
14641464
ret = FAIL;
@@ -1469,7 +1469,8 @@ php_mysqlnd_read_row_ex(MYSQLND_CONN_DATA * conn, MYSQLND_MEMORY_POOL * result_s
14691469

14701470
if (first_iteration) {
14711471
first_iteration = FALSE;
1472-
*buffer = result_set_memory_pool->get_chunk(result_set_memory_pool, *data_size);
1472+
*buffer = result_set_memory_pool->get_chunk(
1473+
result_set_memory_pool, *data_size + prealloc_more_bytes);
14731474
if (!*buffer) {
14741475
ret = FAIL;
14751476
break;
@@ -1484,7 +1485,7 @@ php_mysqlnd_read_row_ex(MYSQLND_CONN_DATA * conn, MYSQLND_MEMORY_POOL * result_s
14841485
/*
14851486
We have to realloc the buffer.
14861487
*/
1487-
if (FAIL == (*buffer)->resize_chunk((*buffer), *data_size)) {
1488+
if (FAIL == (*buffer)->resize_chunk((*buffer), *data_size + prealloc_more_bytes)) {
14881489
SET_OOM_ERROR(*conn->error_info);
14891490
ret = FAIL;
14901491
break;
@@ -1507,7 +1508,6 @@ php_mysqlnd_read_row_ex(MYSQLND_CONN_DATA * conn, MYSQLND_MEMORY_POOL * result_s
15071508
(*buffer)->free_chunk((*buffer));
15081509
*buffer = NULL;
15091510
}
1510-
*data_size -= prealloc_more_bytes;
15111511
DBG_RETURN(ret);
15121512
}
15131513
/* }}} */

0 commit comments

Comments
 (0)