Skip to content

Commit f64be0b

Browse files
committed
Fixed bug #73793 (WDDX uses wrong decimal seperator)
The WDDX specification[1] requires to serialize floats with a decimal point, but `snprintf()` is locale-dependent and may use a decimal comma. We fix that afterwards by replacing an eventual comma with a point. [1] <http://xml.coverpages.org/wddx0090-dtd-19980928.txt>
1 parent 472b259 commit f64be0b

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ PHP NEWS
5858
. Fixed bug #75054 (A Denial of Service Vulnerability was found when
5959
performing deserialization). (Nikita)
6060

61+
- WDDX:
62+
. Fixed bug #73793 (WDDX uses wrong decimal seperator). (cmb)
63+
6164
- XMLRPC:
6265
. Fixed bug #74975 (Incorrect xmlrpc serialization for classes with declared
6366
properties). (blar)

ext/wddx/tests/bug73793.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #73793 (WDDX uses wrong decimal seperator)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('wddx')) print 'skip wddx extension not available';
6+
if (setlocale(LC_NUMERIC, ['de_DE', 'de_DE.UTF-8', 'de-DE']) === false) {
7+
print 'skip German locale not available';
8+
}
9+
?>
10+
--FILE--
11+
<?php
12+
setlocale(LC_NUMERIC , ['de_DE', 'de_DE.UTF-8', 'de-DE']);
13+
var_dump(wddx_serialize_value(['foo' => 5.1]));
14+
?>
15+
===DONE===
16+
--EXPECT--
17+
string(120) "<wddxPacket version='1.0'><header/><data><struct><var name='foo'><number>5.1</number></var></struct></data></wddxPacket>"
18+
===DONE===

ext/wddx/wddx.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,15 @@ static void php_wddx_serialize_string(wddx_packet *packet, zval *var)
420420
*/
421421
static void php_wddx_serialize_number(wddx_packet *packet, zval *var)
422422
{
423-
char tmp_buf[WDDX_BUF_LEN];
423+
char tmp_buf[WDDX_BUF_LEN], *dec_point;
424424
zend_string *str = zval_get_string(var);
425425
snprintf(tmp_buf, sizeof(tmp_buf), WDDX_NUMBER, ZSTR_VAL(str));
426426
zend_string_release(str);
427427

428+
dec_point = strchr(tmp_buf, ',');
429+
if (dec_point) {
430+
*dec_point = '.';
431+
}
428432
php_wddx_add_chunk(packet, tmp_buf);
429433
}
430434
/* }}} */

0 commit comments

Comments
 (0)