修复编译后的程序通过 Zend VM 调用自身的函数,如果此时临时变量过多,会导致段错误的问题 #47

Merged
韩天峰 merged 2 commits from fix/include_require_file into master 2 weeks ago
  1. 4
      src/CompilerBase.php
  2. 35
      tests/compiler/include_require/001.phpt
  3. 3
      tests/compiler/include_require/Hello.php
  4. 1
      tests/compiler/include_require/no-leak.ini

@ -3544,7 +3544,9 @@ class CompilerBase implements PropertyAccessContext
break;
}
return 'php::include(' . $this->parseIdentifier($expr->expr) . ', ' . $type . ')';
$fileName = $this->parseIdentifier($expr->expr);
return "php::include(php::Var($fileName), $type)";
}
protected function parseScalarFloat(Node\Scalar\Float_ $expr): string

@ -0,0 +1,35 @@
--TEST--
include/require unwind safely when ZendVM calls a compiled function that throws
--ENV--
PHPRC=tests/compiler/include_require/no-leak.ini
--FILE--
<?php
declare(strict_types=1);
function Hello(string $value) {}
function includePath(string $name): string
{
return implode('', [__DIR__, '/', ucfirst(strtolower($name)), '.php']);
}
function main(): void
{
// Keep this name: generated helper variables must not collide with PHP locals.
$filename = includePath('hello');
try {
include $filename;
} catch (ArgumentCountError $e) {
echo "include ArgumentCountError\n";
}
try {
require includePath('hello');
} catch (ArgumentCountError $e) {
echo "require ArgumentCountError\n";
}
}
?>
--EXPECT--
include ArgumentCountError
require ArgumentCountError

@ -0,0 +1,3 @@
<?php
declare(strict_types=1);
Hello();
Loading…
Cancel
Save