Skip to content

Commit

Permalink
Fix #74779: x() and y() truncating floats to integers
Browse files Browse the repository at this point in the history
We must not use the locale dependent `atof()`, but instead use the
(hopefully) locale independent `zend_strtod()`, when converting string
representations of floating point numbers which are sent by the server.

Closes GH-6665.
  • Loading branch information
cmb69 committed Feb 5, 2021
1 parent 8b7aaad commit 3f8d21b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2021, PHP 7.4.16

- MySQLi:
. Fixed bug #74779 (x() and y() truncating floats to integers). (cmb)

- OPcache:
. Fixed bug #80682 (opcache doesn't honour pcre.jit option). (Remi)

Expand Down
42 changes: 42 additions & 0 deletions ext/mysqli/tests/bug74779.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--TEST--
Bug #74779 (x() and y() truncating floats to integers)
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnectfailure.inc');
if (!setlocale(LC_NUMERIC, "de_DE", "de_DE.UTF-8", "de-DE")) die('skip locale not available');
?>
--FILE--
<?php
require_once("connect.inc");

if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
$host, $user, $db, $port, $socket);
}

if (!setlocale(LC_NUMERIC, "de_DE", "de_DE.UTF-8", "de-DE")) {
echo "[002] Cannot set locale\n";
}

if (!$link->options(MYSQLI_OPT_INT_AND_FLOAT_NATIVE, true)) {
printf("[003] [%d] %s\n", $link->errno, $link->error);
}

if (!$result = $link->query("SELECT Y(Point(56.7, 53.34))")) {
printf("[004] [%d] %s\n", $link->errno, $link->error);
}

if (!$array = $result->fetch_array(MYSQLI_ASSOC)) {
printf("[005] [%d] %s\n", $link->errno, $link->error);
}

var_dump($array);

mysqli_close($link);
?>
--EXPECT--
array(1) {
["Y(Point(56.7, 53.34))"]=>
float(53,34)
}
2 changes: 1 addition & 1 deletion ext/mysqlnd/mysqlnd_wireprotocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ php_mysqlnd_rowp_read_text_protocol_aux(MYSQLND_ROW_BUFFER * row_buffer, zval *
zend_uchar save = *(p + len);
/* We have to make it ASCIIZ temporarily */
*(p + len) = '\0';
ZVAL_DOUBLE(current_field, atof((char *) p));
ZVAL_DOUBLE(current_field, zend_strtod((char *) p, NULL));
*(p + len) = save;
}
#endif /* MYSQLND_STRING_TO_INT_CONVERSION */
Expand Down

0 comments on commit 3f8d21b

Please sign in to comment.