Bug #79714 [Com]: Extension bcgen + PHAR archives appear not to be able to work together

From: Date: Thu, 18 Jun 2020 21:00:37 +0000
Subject: Bug #79714 [Com]: Extension bcgen + PHAR archives appear not to be able to work together
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227547@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79714&edit=1 ID: 79714 Comment by: henry dot wood dot dk at gmail dot com Reported by: henry dot wood dot dk at gmail dot com Summary: Extension bcgen + PHAR archives appear not to be able to work together Status: Feedback Type: Bug Package: PHAR related Operating System: Ubuntu 18.04 PHP Version: 7.2.31 Block user comment: N Private report: N New Comment: As BCGEN is based on opcache code, I would - ideally - very much like for someone in the PHP Team to reach out to the BCGEN authors (either the opcache code authors and/or the PHAR authors) and help the authors of BCGEN as it is my feeling that the authors of BCGEN have admitted to not knowing enough about opcache code and/or PHAR extension in order to solve the problem on their own. The goal would then - of course - be to benefit the BCGEN extension in such a way that it will become compatible with PHP version 7.2+. Ultimately, I would like to achieve a situation where PHARs can be used to distribute applications in a way/format which is not so easily reverse engineered. This would indeed benefit the entire PHP community in my humble opinion. I think it is about time that it becomes possible to distribute PHARs in a secure manner. Previous Comments: ------------------------------------------------------------------------ [2020-06-18 20:30:59] henry dot wood dot dk at gmail dot com I have previously reported what I think is the same bug to bcgen - Please see: https://github.com/vjardin/bcgen/issues/10 Also running the simple.phar file on the command line, yields an exit code of 130. ------------------------------------------------------------------------ [2020-06-18 20:21:15] nikic@php.net Do you have any specific reason to believe this issue is on the phar side rather than the bcgen side? I would recommend reporting the issue with bcgen first. As the project is compatible only with PHP 7.2 and PHP 7.2 is no longer actively supported, we will not be able to fix anything anyway (though if the issue is indeed on the phar side, future versions may be fixed -- that's a big if though). ------------------------------------------------------------------------ [2020-06-18 20:11:29] henry dot wood dot dk at gmail dot com Possible conclusion: Any compiled file *WITHIN* the phar archive 'simple.phar' is simply read as-is and not parsed/evaluated/executed - however, the BCGEN header appears to be stripped from the output. Any normal PHP file *WITHIN* the phar archive 'simple.phar' is read, parsed, evaluted and executed as expected. ------------------------------------------------------------------------ [2020-06-18 20:09:41] henry dot wood dot dk at gmail dot com Description: ------------ I am trying to build a PHAR archive which contains both files compiled by bcgen (See: https://github.com/vjardin/bcgen) and normal PHP files I would then expect the PHAR file to be runnable via the command line, regardless which type of file is referenced (either a bcgen compiled file or a normal php file) as this is what is explained in the README of bcgen. NOTE: Also note that this INI setting should be set: bcgen.enable (default "1") BCgen On/Off switch. When set to Off, bytecode files cannot be read Test script: --------------- <?php // CHECK FOR BCGEN if (! extension_loaded('Zend BCgen')) { echo "ERROR: Needs Zend BCgen extension".PHP_EOL; die(-1); } // COMPILE test.phb FROM test.php // CONTENTS OF test.php: <?php echo "HELLO FROM BCGEN...".PHP_EOL; file_put_contents('test.php', '<?php echo "HELLO FROM BCGEN...".PHP_EOL;'); bcgen_compile_file('test.php', 'b.phb'); // MAKE test2.php file_put_contents('test2.php', '<?php echo "HELLO FROM NORMAL PHP...".PHP_EOL;'); // Make PHAR $phar = new Phar( 'simple.phar' ); $phar->addFile('test.phb', 'b.phb'); $phar->addFile('test2.php', 'c.php'); $phar['a.php'] = '<?php echo "Hola Mundo\n"; include("b.phb"); include("c.php")?>'; $pharfile = 'simple.phar'; $startfile = 'a.php'; $stub = <<< "EOT" #!/usr/bin/env php <?php Phar::mapPhar( '$pharfile' ); set_include_path( 'phar://' . __FILE__ . PATH_SEPARATOR . get_include_path() ); require( '$startfile' ); __HALT_COMPILER(); EOT; $phar->setStub( $stub ); echo "DONE ...".PHP_EOL; Expected result: ---------------- After running the test script to build the PHAR archive, I would expect running the simple.phar file from command line to output: Expected output: Hola Mundo HELLO FROM BCGEN... HELLO FROM NORMAL PHP... Actual result: -------------- Actual output: Hola Mundo /tmp/test.php▒▒▒▒▒▒▒▒▒`▒f/▒,▒HELLO FROM BCGEN... i▒▒▒▒> HELLO FROM NORMAL PHP... ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79714&edit=1

« previous php.bugs (#227547) next »