Bug #64912 [Com]: Unexpected output when parsing PHP files containing NUL characters

From: Date: Tue, 15 Oct 2013 12:18:28 +0000
Subject: Bug #64912 [Com]: Unexpected output when parsing PHP files containing NUL characters
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-182282@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64912&edit=1

 ID:                 64912
 Comment by:         alexander dot stehlik at gmail dot com
 Reported by:        alexander dot stehlik at gmail dot com
 Summary:            Unexpected output when parsing PHP files containing
                     NUL characters
 Status:             No Feedback
 Type:               Bug
 Package:            mbstring related
 Operating System:   Linux (Ubuntu and CentOS)
 PHP Version:        5.4.15
 Block user comment: N
 Private report:     N

 New Comment:

This is really strange. When I run this script:

<?php
$var = 'here is ^@ null';
?>

with PHP 5.4.16 I get this output:

$ php -n -d zend.multibyte=on -d mbstring.internal_encoding=utf-8 test.php

㰿灨瀊⑶慲‽‧桥牥⁩猠 湵/


Previous Comments:
------------------------------------------------------------------------
[2013-10-15 11:54:43] php-bugs at lists dot php dot net

No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.

------------------------------------------------------------------------
[2013-06-29 05:25:33] yohgaki@php.net

With 5.4.16, I get

$ php -n -d mbstring.internal_encoding=utf-8 test.php 
testTEST

$ php -n -d zend.multibyte=on -d mbstring.internal_encoding=utf-8 test.php 

Fatal error: Could not convert the script from the detected encoding "UTF-16BE" 
to a compatible encoding in Unknown on line 0

test.php
<?php echo "test^@TEST";?>
where ^@ is actual null char.
e.g. $ echo -e "<?php echo \"test\0TEST\";?>" > test.php


With some Japanese, I got the same result.

$ php -n -d mbstring.internal_encoding=utf-8 test.php 
日本語あいうえおtestTEST

$ php -n -d zend.multibyte=on -d mbstring.internal_encoding=utf-8 test.php

Fatal error: Could not convert the script from the detected encoding "UTF-16BE" 
to a compatible encoding in Unknown on line 0


Are you using the exact same test script or using more complex script?

------------------------------------------------------------------------
[2013-05-23 17:31:10] alexander dot stehlik at gmail dot com

Description:
------------
When this setting is used:

zend.multibyte = On

and I parse a PHP file that contains a NUL character (this one here: 
http://en.wikipedia.org/wiki/Null_character)
I get some weird output.

When I do not use the mbstring.internal_encoding setting I get a lot of question 
marks (?).

When I use mbstring.internal_encoding = utf-8 I get some characters that look 
like Chinese to me.

Test script:
---------------
<?php

// I can not insert the NUL character here.
// To put it in a PHP file you can use the console:
//
// echo -e "here is \0 null" >> test.php

$var = 'here is <InsertNULCharacterHere> null';
?>

Expected result:
----------------
When I run the given example with

php test.php

I expect no output, even when this setting is active:

zend.multibyte = On


Actual result:
--------------
With the setting

zend.multibyte = On

I get some weird output (depending on the configured internal encoding):

With the setting

mbstring.internal_encoding = utf-8

I get an output that looks like this:

㰿灨瀊⑶慲‽‧桥物⁳椠 湵汬✻ਿ㸊

Without the setting the output looks like this:

??????????? ?????




------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=64912&edit=1


Thread (4 messages)

« previous php.bugs (#182282) next »