php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64912 Unexpected output when parsing PHP files containing NUL characters
Submitted: 2013-05-23 17:31 UTC Modified: 2013-10-15 11:54 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: alexander dot stehlik at gmail dot com Assigned:
Status: No Feedback Package: mbstring related
PHP Version: 5.4.15 OS: Linux (Ubuntu and CentOS)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: alexander dot stehlik at gmail dot com
New email:
PHP Version: OS:

 

 [2013-05-23 17:31 UTC] 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:

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



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-06-29 05:25 UTC] yohgaki@php.net
-Status: Open +Status: Feedback
 [2013-06-29 05:25 UTC] 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-10-15 11:54 UTC] 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-10-15 12:18 UTC] alexander dot stehlik at gmail dot com
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

㰿灨瀊⑶慲‽‧桥牥⁩猠 湵/
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 17:01:29 2024 UTC