#38900 [NEW]: wddx mangles utf8 characters in serialized strings

From: Date: Wed, 20 Sep 2006 13:40:18 +0000
Subject: #38900 [NEW]: wddx mangles utf8 characters in serialized strings
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-102473@lists.php.net to get a copy of this message
From: grzegorz dot nosek at netart dot pl Operating system: Linux PHP version: 4.4.4 PHP Bug Type: WDDX related Bug description: wddx mangles utf8 characters in serialized strings Description: ------------ wddx gets confused if you try to serialize a string with utf8 characters (like the one below, it contains 'z with dot above', 'o acute', 'l stroke' and 'w' - in case it gets messed up somehow). serialized string will contain <char code='C5'/><char code='BC'/> ... etc, which will get fed into xml_utf8_decode byte by byte (after decoding the hex value), totally wrecking the output. Hackish patch which fixes this (whitespace mangled mercilessly, adjust to taste): --- a/ext/wddx/wddx.c +++ b/ext/wddx/wddx.c @@ -1038,8 +1038,13 @@ static void php_wddx_process_data(void * if (!wddx_stack_is_empty(stack) && !stack->done) { wddx_stack_top(stack, (void**)&ent); switch (Z_TYPE_P(ent)) { - case ST_STRING: - decoded = xml_utf8_decode(s, len, &decoded_len, "ISO-8859-1"); + case ST_STRING: + if (len > 1) { + decoded = xml_utf8_decode(s, len, &decoded_len, "ISO-8859-1"); + } else { + decoded = estrndup(s, len); + decoded_len = len; + } if (Z_STRLEN_P(ent->data) == 0) { Z_STRVAL_P(ent->data) = estrndup(decoded, decoded_len); Reproduce code: --------------- --TEST-- wddx_deserialize mangles utf8 characters --SKIPIF-- <?php if (!extension_loaded("wddx")) print "skip"; ?> --FILE-- <?php $zolw = iconv("ISO-8859-2", "UTF-8", "&#380;ó&#322;w"); $in = array ( $zolw => $zolw ); var_dump(array_diff($in, wddx_deserialize(wddx_serialize_value($in)))); ?> --EXPECT-- array(0) { } -- Edit bug report at http://bugs.php.net/?id=38900&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=38900&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=38900&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=38900&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=38900&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=38900&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=38900&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=38900&r=needscript Try newer version: http://bugs.php.net/fix.php?id=38900&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=38900&r=support Expected behavior: http://bugs.php.net/fix.php?id=38900&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=38900&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=38900&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=38900&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38900&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=38900&r=dst IIS Stability: http://bugs.php.net/fix.php?id=38900&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=38900&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=38900&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=38900&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=38900&r=mysqlcfg

« previous php.bugs (#102473) next »