php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48930 __COMPILER_HALT_OFFSET__ incorrect in PHP>=5.3
Submitted: 2009-07-15 17:40 UTC Modified: 2010-06-30 04:46 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:1 (33.3%)
From: adam-phpbugs at adam dot gs Assigned: felipe
Status: Closed Package: Scripting Engine problem
PHP Version: 5.3, 6 OS: *
Private report: No CVE-ID:
 [2009-07-15 17:40 UTC] adam-phpbugs at adam dot gs
Description:
------------
Starting in PHP 5.3.0, php no longer includes the shebang when 
calculating the __COMPILER_HALT_OFFSET__.

Reproduce code:
---------------
#!/usr/bin/php
<?php
printf("__COMPILER_HALT_OFFSET__ is %d\n",__COMPILER_HALT_OFFSET__);


__halt_compiler();


Expected result:
----------------
-=[~]=- -=[Wed Jul 15]=- -=[13:35:18]=-
[adam@nighe]$ php  -v
PHP 5.3.0 (cli) (built: Jul  7 2009 15:11:49) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies

-=[~]=- -=[Wed Jul 15]=- -=[13:35:52]=-
[adam@nighe]$ php-stock -v
PHP 5.2.8 (cli) (built: Feb  5 2009 21:21:13) 
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies

-=[~]=- -=[Wed Jul 15]=- -=[13:37:38]=-
[adam@nighe]$ php test.php 
__COMPILER_HALT_OFFSET__ is 94

-=[~]=- -=[Wed Jul 15]=- -=[13:37:39]=-
[adam@nighe]$ php-stock test.php
__COMPILER_HALT_OFFSET__ is 109


The latter answer in this case is correct, the shebang from the above 
example is exactly 15 bytes with the newline, 109-15 == 94. So PHP is 
not including the shebang in the __COMPILER_HALT_OFFSET__ calculation.

Actual result:
--------------
94!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-16 00:23 UTC] kalle@php.net
Scott, you worked on the re2c switch, any chance you can clarrify this one?
 [2009-08-03 03:06 UTC] scottmac@php.net
The sapi/cli/php_cli.c code will read forward when it see's a shebang  to the next line. The file is already seeked by the time the scanner gets a change to look at it.

The zend_get_scanned_file_offset() doesn't know about this because by the time the scanner is started the bytes are already long gone.

Short of a global variable I'm not seeing a clean way to fix this.
 [2009-08-30 22:56 UTC] adam-phpbugs at adam dot gs
Understandably this might be a bit hackish to have use a global variable 
here, but perhaps thats preferable to what i'd consider a major 
regression?

I attempted to patch this so I could just submit a patch here, but 
unfortunately my c-fu and my understanding of PHP internals is lacking.
 [2009-09-09 19:56 UTC] jani@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

Since the shebang check was removed from scanner, isn't this issue 
solved then? (please try :)
 [2009-09-09 20:02 UTC] jani@php.net
Nevermind, of course it's still borked since the check is NOT done in 
scanner. :)
 [2010-05-26 11:32 UTC] daniel dot haas at cn-consult dot eu
We also hit this bug, because we have a custom php-based installer that uses __halt_compiler() and __COMPILER_HALT_OFFSET__ to extract a tar.gz portion of the installer.
Since PHP 5.3 our installers do not work anymore! :-(
Is a fix not even planned at this stage??
 [2010-06-27 23:46 UTC] felipe@php.net
-Status: Assigned +Status: Closed
 [2010-06-27 23:46 UTC] felipe@php.net
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.


 [2010-06-27 23:46 UTC] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=300789
Log: - Fixed bug #48930 (__COMPILER_HALT_OFFSET__ incorrect in PHP &gt;= 5.3)
 [2010-06-27 23:46 UTC] felipe@php.net
-Assigned To: scottmac +Assigned To: felipe
 [2010-06-28 00:16 UTC] adam-phpbugs at adam dot gs
Hi felipe,
Thanks for taking a look at this bug, its languished for (what i'd consider) far 
too long.
Unfortunately it doesn't seem to fix the issue:

-=[~/Scripts/compile/php5.3-201006272030]=- -=[Sun Jun 27]=- -=[18:14:16]=-
[adam@nighe]$ ./sapi/cli/php -v
PHP 5.3.3RC2-dev (cli) (built: Jun 27 2010 17:54:04) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
-=[~/Scripts/compile/php5.3-201006272030]=- -=[Sun Jun 27]=- -=[18:15:11]=-
[adam@nighe]$ php -v
PHP 5.3.1 (cli) (built: Dec 26 2009 19:21:45) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
-=[~/Scripts/compile/php5.3-201006272030]=- -=[Sun Jun 27]=- -=[18:15:15]=-
[adam@nighe]$ ./sapi/cli/php test-without-shebang.php 
string(19) "
this is test data
"
-=[~/Scripts/compile/php5.3-201006272030]=- -=[Sun Jun 27]=- -=[18:15:30]=-
[adam@nighe]$ ./sapi/cli/php test-with-shebang.php 
string(40) ");
__halt_compiler();
this is test data
"
-=[~/Scripts/compile/php5.3-201006272030]=- -=[Sun Jun 27]=- -=[18:15:34]=-
[adam@nighe]$ php test-with-shebang.php 
string(40) ");
__halt_compiler();
this is test data
"
-=[~/Scripts/compile/php5.3-201006272030]=- -=[Sun Jun 27]=- -=[18:15:38]=-
[adam@nighe]$ php test-without-shebang.php 
string(19) "
this is test data
"
-=[~/Scripts/compile/php5.3-201006272030]=- -=[Sun Jun 27]=- -=[18:15:44]=-
[adam@nighe]$ cat test-without-shebang.php 
<?php
$fh=fopen(__FILE__,"r");
fseek($fh,__COMPILER_HALT_OFFSET__);
var_dump(fread($fh,1024));
fclose($fh);
__halt_compiler();
this is test data
-=[~/Scripts/compile/php5.3-201006272030]=- -=[Sun Jun 27]=- -=[18:15:54]=-
[adam@nighe]$ cat test-with-shebang.php 
#!/usr/local/bin/php
<?php
$fh=fopen(__FILE__,"r");
fseek($fh,__COMPILER_HALT_OFFSET__);
var_dump(fread($fh,1024));
fclose($fh);
__halt_compiler();
this is test data
 [2010-06-28 00:41 UTC] adam-phpbugs at adam dot gs
I lied, It just hasn't hit the snapshots yet, works from SVN sources!

-=[~/Scripts/compile/php-src-5.3]=- -=[Sun Jun 27]=- -=[18:40:12]=-
[adam@nighe]$ ./sapi/cli/php test-with-shebang.php 
string(19) "
this is test data
"
-=[~/Scripts/compile/php-src-5.3]=- -=[Sun Jun 27]=- -=[18:40:17]=-
[adam@nighe]$ ./sapi/cli/php test-without-shebang.php 
string(19) "
this is test data
"


Thanks very much felipe!
 [2010-06-29 13:37 UTC] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=300854
Log: - Reverted fix for bug #48930 (due binary compatibility breakage)
 [2010-06-29 13:54 UTC] felipe@php.net
The fix has been reverted for 5.3 branch because it breaks binary compatibility.
 [2010-06-29 18:44 UTC] adam-phpbugs at adam dot gs
Thats awesome....
 [2010-06-29 18:44 UTC] adam-phpbugs at adam dot gs
Can you fix the status of this bug then, its not closed nor is it resolved.
 [2010-06-29 19:40 UTC] rasmus@php.net
It is fixed in trunk, so technically it has been fixed.  It may be a "Can't Fix" 
for 5.3 if Felipe can't find a way to fix it without breaking binary compatibility 
in a minor release version.
 [2010-06-30 04:30 UTC] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=300869
Log: - MF5.3: Reverted fix for bug #48930 (due binary compatibility breakage)
# To commit a new common fix
 [2010-06-30 04:33 UTC] kalle@php.net
-Status: Closed +Status: Assigned
 [2010-06-30 04:45 UTC] felipe@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=300871
Log: - Fixed bug #48930 (__COMPILER_HALT_OFFSET__ incorrect in PHP &gt;= 5.3)
 [2010-06-30 04:46 UTC] felipe@php.net
-Status: Assigned +Status: Closed
 [2010-06-30 04:46 UTC] felipe@php.net
I've committed a new fix for this bug, in 5.3 and trunk.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sat Apr 19 19:02:15 2014 UTC