Skip to content

Commit 1592344

Browse files
committed
Fix value that is bigger than INT64_MAX will be casted to INT64_MAX rather than string.
1 parent a529d0d commit 1592344

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

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+
(uint64_t) strtoull((char *) p, NULL, 10);
16181618
#else
1619-
(uint64_t) _atoi64((char *) p);
1619+
(uint64_t) _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: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
--TEST--
2+
Fix value that is bigger than INT64_MAX will be casted to INT64_MAX rather than string.
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 (9223372036854775807)");
24+
$pdo->query("INSERT INTO $tbl (`ubigint`) VALUES (1)");
25+
$result = $pdo->query("SELECT ubigint FROM $tbl")->fetchAll(PDO::FETCH_ASSOC);
26+
var_dump($result);
27+
?>
28+
--CLEAN--
29+
<?php
30+
require dirname(__FILE__) . '/mysql_pdo_test.inc';
31+
MySQLPDOTest::dropTestTable();
32+
?>
33+
--EXPECT--
34+
array(4) {
35+
[0]=>
36+
array(1) {
37+
["ubigint"]=>
38+
string(20) "18446744073709551615"
39+
}
40+
[1]=>
41+
array(1) {
42+
["ubigint"]=>
43+
string(19) "9223372036854775808"
44+
}
45+
[2]=>
46+
array(1) {
47+
["ubigint"]=>
48+
int(9223372036854775807)
49+
}
50+
[3]=>
51+
array(1) {
52+
["ubigint"]=>
53+
int(1)
54+
}
55+
}

0 commit comments

Comments
 (0)