#43957 [NEW]: utf8_decode() provides random output for bad input

From: Date: Tue, 29 Jan 2008 02:35:03 +0000
Subject: #43957 [NEW]: utf8_decode() provides random output for bad input
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-121694@lists.php.net to get a copy of this message
From: penguin@php.net Operating system: linux debian 4.0 PHP version: 5.2.5 PHP Bug Type: Unknown/Other Function Bug description: utf8_decode() provides random output for bad input Description: ------------ utf8_decode() outputs a random character when supplied with bad input. When invalid sequences are added, utf8_decoded() usually replace the sequence with the character "?". But when a lonely highbit character is present in the end the output seem to be a random character. Reproduce code: --------------- for($a=0;$a<20;$a++)printf("%02x ",utf8_decode(chr(0xE0))); Expected result: ---------------- 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f 3f (utf8_decode() returns a question mark) Actual result: -------------- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 or 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 09 or 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 05 or 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 or some other random value It seem to differ more with individual runs: $ for a in seq 1 20; do php -r 'printf("%02x ",utf8_decode(chr(0xE0)));'; done 08 00 00 02 00 00 00 00 00 05 00 00 00 05 00 00 07 00 09 00 -- Edit bug report at http://bugs.php.net/?id=43957&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43957&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43957&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43957&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43957&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=43957&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=43957&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=43957&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=43957&r=needscript Try newer version: http://bugs.php.net/fix.php?id=43957&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=43957&r=support Expected behavior: http://bugs.php.net/fix.php?id=43957&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=43957&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=43957&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=43957&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43957&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=43957&r=dst IIS Stability: http://bugs.php.net/fix.php?id=43957&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=43957&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=43957&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=43957&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=43957&r=mysqlcfg

« previous php.bugs (#121694) next »