Skip to content

Commit

Permalink
Fix php-proxying of binaries to avoid proxying phar files, fixes #9742
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Mar 9, 2021
1 parent e9d405f commit 4bedd83
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Composer/Installer/BinaryInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,18 @@ protected function generateUnixyProxyCode($bin, $link)
$binFile = basename($binPath);

$binContents = file_get_contents($bin);
// For php files, we generate a PHP proxy instead of a shell one,
// which allows calling the proxy with a custom php process
if (preg_match('{^(?:#!(?:/usr)?/bin/env php|#!(?:/usr)?/bin/php|<?php)\r?\n}', $binContents, $match)) {
$proxyCode = trim($match[0]);
// carry over the existing shebang if present, otherwise add our own
if ($proxyCode === "<?php") {
$proxyCode = "#!/usr/bin/env php";
}
$binPathExported = var_export($binPath, true);
return $proxyCode . "\n" . <<<PROXY
// verify the file is not a phar file, because those do not support php-proxying
if (false === ($pos = strpos($binContents, '__HALT_COMPILER')) || false === strpos(substr($binContents, 0, $pos), 'Phar::mapPhar')) {
$proxyCode = trim($match[0]);
// carry over the existing shebang if present, otherwise add our own
if ($proxyCode === "<?php") {
$proxyCode = "#!/usr/bin/env php";
}
$binPathExported = var_export($binPath, true);
return $proxyCode . "\n" . <<<PROXY
<?php
/**
Expand All @@ -225,6 +229,7 @@ protected function generateUnixyProxyCode($bin, $link)
include \$binPath;
PROXY;
}
}

$proxyCode = <<<PROXY
Expand Down

0 comments on commit 4bedd83

Please sign in to comment.