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

NathanFreeman 2 weeks ago
parent 2be13eefcd
commit 3cade8a505
  1. 21
      src/CompilerBase.php
  2. 17
      tests/compiler/include_require/001.phpt
  3. 3
      tests/compiler/include_require/Hello.php

@ -3510,7 +3510,26 @@ class CompilerBase implements PropertyAccessContext
break;
}
return 'php::include(' . $this->parseIdentifier($expr->expr) . ', ' . $type . ')';
/**
* If an included PHP file encounters a fatal error during execution—for example,
* incorrect function arguments—an exception will be thrown, unwinding directly from
* the Zend VM stack through the C++ stack. In the original implementation,
* there were several "undestroyed temporary objects." When the exception propagates back,
* those objects need to be destroyed. However, by that time the environment
* is already in a corrupted/inconsistent state, and attempting to destroy them causes a crash.
*/
$fileName = $this->parseIdentifier($expr->expr);
return <<<EOL
zend_string *filename = nullptr;
{
php::Str temp = $fileName;
filename = temp.str();
zend_string_addref(filename);
}
php::include(filename, $type)
EOL;
}
protected function parseScalarFloat(Node\Scalar\Float_ $expr): string

@ -0,0 +1,17 @@
--TEST--
The compiled program calls its own functions via the Zend VM.
--FILE--
<?php
declare(strict_types=1);
function Hello(string $value) {}
function main() {
try {
require __DIR__ . '/Hello.php';
} catch (ArgumentCountError $e) {
echo "ArgumentCountError Error";
}
}
?>
--EXPECT--
ArgumentCountError Error

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