From:             post at wickenrode dot com
Operating system: Xubuntu 12.10 amd64
PHP version:      5.4.8
Package:          Unicode Engine related
Bug Type:         Bug
Bug description:Files declared as UTF-8 will append NUL bytes to output for non 
ASCII character

Description:
------------
Take the test script below and save it as UTF-8 and verify:

> cat test.php | tail -n 4 | head -n 1 | hexdump -C
00000000  09 23 20 c3 a4 c3 b6 0a                           |.# .....|
00000008

Now run

> ./bin/php test.php | hexdump -C
PHP Version = 5.4.8
zend.multibyte = 1
00000000  58 00 00 00                                       |X...|
00000004

As you can see PHP added three NUL bytes to the file.
Now remove one of the characters in the commented out line:

> ./bin/php test.php | hexdump -C
PHP Version = 5.4.8
zend.multibyte = 1
00000000  58 00 00                                          |X..|
00000003

As you can see the NUL bytes are directly related to the amount of
non-ASCII characters in the file.

Now comment out the declare statement:

> ./bin/php test.php | hexdump -C
PHP Version = 5.4.8
zend.multibyte = 1
00000000  58                                                |X|
00000001

This time the output is correct.

Tested with off-the-shelf PHP, but also happens with ubuntu packaged
5.4.6-1
Also happends when PHP is running as Apache module where this issue caused
corrupted images for me.

Test script:
---------------
<?php
        declare(encoding='UTF-8');

        fwrite(STDERR,"PHP Version = ".phpversion()."\n");
        fwrite(STDERR,"zend.multibyte = ".ini_get('zend.multibyte')."\n");

        # äöü
        echo "X";

?>


Expected result:
----------------
See above.
UTF-8 declared files with UTF-8 content should work fine.

Actual result:
--------------
See above.
UTF-8 declared files with UTF-8 content produce NUL bytes in the output.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=63316&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=63316&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=63316&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=63316&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=63316&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=63316&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=63316&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=63316&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=63316&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=63316&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=63316&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=63316&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=63316&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=63316&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63316&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=63316&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=63316&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=63316&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=63316&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=63316&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=63316&r=mysqlcfg

Reply via email to