Skip to content

Commit 15233a4

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix bug where large bigints may be truncated
2 parents 55a4bae + ae9e986 commit 15233a4

File tree

3 files changed

+95
-2
lines changed

3 files changed

+95
-2
lines changed

ext/mysqli/tests/gh7837.phpt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
--TEST--
2+
Bug GH-7837 (large bigints may be truncated)
3+
--EXTENSIONS--
4+
mysqli
5+
--SKIPIF--
6+
<?php
7+
require_once("connect.inc");
8+
if (strpos(mysqli_get_client_info(), "mysqlnd") === false) {
9+
die("skip requires mysqlnd");
10+
}
11+
require_once("skipifconnectfailure.inc");
12+
?>
13+
--FILE--
14+
<?php
15+
require_once("connect.inc");
16+
17+
$mysql = new mysqli($host, $user, $passwd, $db, $port, $socket);
18+
$mysql->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true);
19+
$mysql->query("DROP TABLE IF EXISTS test");
20+
$mysql->query("CREATE TABLE test (`ubigint` bigint unsigned NOT NULL) ENGINE=InnoDB");
21+
$mysql->query("INSERT INTO test (`ubigint`) VALUES (18446744073709551615)");
22+
$mysql->query("INSERT INTO test (`ubigint`) VALUES (9223372036854775808)");
23+
$mysql->query("INSERT INTO test (`ubigint`) VALUES (1)");
24+
$result = $mysql->query("SELECT ubigint FROM test");
25+
var_dump($result->fetch_all());
26+
?>
27+
--EXPECT--
28+
array(3) {
29+
[0]=>
30+
array(1) {
31+
[0]=>
32+
string(20) "18446744073709551615"
33+
}
34+
[1]=>
35+
array(1) {
36+
[0]=>
37+
string(19) "9223372036854775808"
38+
}
39+
[2]=>
40+
array(1) {
41+
[0]=>
42+
int(1)
43+
}
44+
}

ext/mysqlnd/mysqlnd_wireprotocol.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,9 +1614,9 @@ php_mysqlnd_rowp_read_text_protocol(MYSQLND_ROW_BUFFER * row_buffer, zval * fiel
16141614
} else {
16151615
uint64_t v =
16161616
#ifndef PHP_WIN32
1617-
(uint64_t) atoll((char *) p);
1617+
strtoull((char *) p, NULL, 10);
16181618
#else
1619-
(uint64_t) _atoi64((char *) p);
1619+
_strtoui64((char *) p, NULL, 10);
16201620
#endif
16211621
bool uns = fields_metadata[i].flags & UNSIGNED_FLAG? TRUE:FALSE;
16221622
/* We have to make it ASCIIZ temporarily */
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
Bug GH-7837 (large bigints may be truncated)
3+
--EXTENSIONS--
4+
pdo
5+
pdo_mysql
6+
mysqlnd
7+
--SKIPIF--
8+
<?php
9+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
10+
MySQLPDOTest::skip();
11+
if (!MySQLPDOTest::isPDOMySQLnd()) die('skip only for mysqlnd');
12+
?>
13+
--FILE--
14+
<?php
15+
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
16+
$pdo = MySQLPDOTest::factory();
17+
18+
$tbl = "test";
19+
$pdo->query("DROP TABLE IF EXISTS $tbl");
20+
$pdo->query("CREATE TABLE $tbl (`ubigint` bigint unsigned NOT NULL) ENGINE=InnoDB");
21+
$pdo->query("INSERT INTO $tbl (`ubigint`) VALUES (18446744073709551615)");
22+
$pdo->query("INSERT INTO $tbl (`ubigint`) VALUES (9223372036854775808)");
23+
$pdo->query("INSERT INTO $tbl (`ubigint`) VALUES (1)");
24+
$result = $pdo->query("SELECT ubigint FROM $tbl")->fetchAll(PDO::FETCH_ASSOC);
25+
var_dump($result);
26+
?>
27+
--CLEAN--
28+
<?php
29+
require dirname(__FILE__) . '/mysql_pdo_test.inc';
30+
MySQLPDOTest::dropTestTable();
31+
?>
32+
--EXPECT--
33+
array(3) {
34+
[0]=>
35+
array(1) {
36+
["ubigint"]=>
37+
string(20) "18446744073709551615"
38+
}
39+
[1]=>
40+
array(1) {
41+
["ubigint"]=>
42+
string(19) "9223372036854775808"
43+
}
44+
[2]=>
45+
array(1) {
46+
["ubigint"]=>
47+
int(1)
48+
}
49+
}

0 commit comments

Comments
 (0)