Bug #54089 [Opn->Csd]: token_get_all with regards to __halt_compiler is not binary safe

From: Date: Mon, 28 Feb 2011 15:18:35 +0000
Subject: Bug #54089 [Opn->Csd]: token_get_all with regards to __halt_compiler is not binary safe
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-159103@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=54089&edit=1

 ID:                 54089
 Updated by:         iliaa@php.net
 Reported by:        nicolas dot grekas+php at gmail dot com
 Summary:            token_get_all with regards to __halt_compiler is not
                     binary safe
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            Unknown/Other Function
 Operating System:   Any
 PHP Version:        5.3.5
-Assigned To:        
+Assigned To:        iliaa
 Block user comment: N
 Private report:     N

 New Comment:

This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------
[2011-02-28 16:18:28] iliaa@php.net

Automatic comment from SVN on behalf of iliaa
Revision: http://svn.php.net/viewvc/?view=revision&revision=308761
Log: Fixed bug #54089 (token_get_all() does not stop after
__halt_compiler).

------------------------------------------------------------------------
[2011-02-24 13:16:17] nicolas dot grekas+php at gmail dot com

Description:
------------
A. token_get_all() eats some characters which are not allowed in plain
PHP code and trigger a "Unexpected character in input" warning.

B. after a T_HALT_COMPILER, the tokens are still identified as if they
were not after this T_HALT_COMPILER, when in reality they are just
random data.

So, when using token_get_all on code which contains a T_HALT_COMPILER,
the data after that is corrupted because of A.

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

$code = "<?php __halt_compiler();\x01?>\x02";

$tokens = token_get_all($code);
$reconstructed_code = '';

foreach ($tokens as $t)
{
	$reconstructed_code .= isset($t[1]) ? $t[1] : $t;
}

var_dump($code);
var_dump($reconstructed_code);


Expected result:
----------------
string(28) "<?php __halt_compiler();?>"
string(28) "<?php __halt_compiler();?>"


Actual result:
--------------
PHP Warning:  Unexpected character in input:  '' (ASCII=1) state=0 on
line 5
string(28) "<?php __halt_compiler();?>"
string(27) "<?php __halt_compiler();?>"



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



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


Thread (13 messages)

« previous php.bugs (#159103) next »