From 3f8d21b9226493365cbb9f913322f5da6965c974 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 4 Feb 2021 14:43:17 +0100 Subject: Fix #74779: x() and y() truncating floats to integers 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. --- NEWS | 3 +++ ext/mysqli/tests/bug74779.phpt | 42 ++++++++++++++++++++++++++++++++++++++ ext/mysqlnd/mysqlnd_wireprotocol.c | 2 +- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 ext/mysqli/tests/bug74779.phpt diff --git a/NEWS b/NEWS index 0ef6168f56..c9fd50f4f5 100644 --- a/NEWS +++ b/NEWS @@ -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) diff --git a/ext/mysqli/tests/bug74779.phpt b/ext/mysqli/tests/bug74779.phpt new file mode 100644 index 0000000000..88e658ef61 --- /dev/null +++ b/ext/mysqli/tests/bug74779.phpt @@ -0,0 +1,42 @@ +--TEST-- +Bug #74779 (x() and y() truncating floats to integers) +--SKIPIF-- + +--FILE-- +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) +} diff --git a/ext/mysqlnd/mysqlnd_wireprotocol.c b/ext/mysqlnd/mysqlnd_wireprotocol.c index 216f420698..072fdde97a 100644 --- a/ext/mysqlnd/mysqlnd_wireprotocol.c +++ b/ext/mysqlnd/mysqlnd_wireprotocol.c @@ -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 */ -- cgit v1.2.1