Bug #77631 [NEW]: ReflectionClass->isSubclassOf crashes in PHP 7.4 for anonymous class
| From: | tandre@php.net | Date: | Mon, 18 Feb 2019 03:05:32 +0000 |
| Subject: | Bug #77631 [NEW]: ReflectionClass->isSubclassOf crashes in PHP 7.4 for anonymous class | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-219619@lists.php.net to get a copy of this message | ||
From: tandre
Operating system: Linux
PHP version: Next Minor Version
Package: Reproducible crash
Bug Type: Bug
Bug description:ReflectionClass->isSubclassOf crashes in PHP 7.4 for anonymous class
Description:
------------
This was initially reproduced by cloning
https://github.com/Microsoft/tolerant-php-parser
, running
composer.phar install, and running `vendor/bin/phpunit
tests/ParserGrammerTest.php`.
I narrowed the bug down to the below test script. This crashes in both
non-debug NTS and a debug ZTS build in PHP-7.4 (built today with
5b15908ed7d1765c1776b40ffc58092044aa1332, introduced somewhere before
that).
instance_ce has invalid data. This might be caused by the test script
using a ReflectionClass for an anonymous class where no instances have
been created.
```
Checking for class@anonymous/path/to/php-src/test.php0x7ffff7fd405d
Program received signal SIGSEGV, Segmentation fault.
0x0000000000b31505 in instanceof_class (instance_ce=0x4,
ce=0x7fffe4b69c18) at /path/to/php-src/Zend/zend_operators.c:2285
warning: Source file is more recent than executable.
2285 instance_ce = instance_ce->parent;
(gdb) bt
#0 0x0000000000b31505 in instanceof_class (instance_ce=0x4,
ce=0x7fffe4b69c18) at /path/to/php-src/Zend/zend_operators.c:2285
#1 0x0000000000b3168d in instanceof_function
(instance_ce=0x7fffecc06740, ce=0x7fffe4b69c18) at
/path/to/php-src/Zend/zend_operators.c:2330
#2 0x00000000007be3af in zim_reflection_class_isSubclassOf
(execute_data=0x7fffecc171a0, return_value=0x7fffecc17110) at
/path/to/php-src/ext/reflection/php_reflection.c:4991
#3 0x0000000000bb451d in ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER () at
/path/to/php-src/Zend/zend_vm_execute.h:1104
#4 0x0000000000c36376 in execute_ex (ex=0x7fffecc17020) at
/path/to/php-src/Zend/zend_vm_execute.h:61540
#5 0x0000000000c3c999 in zend_execute (op_array=0x7fffecc73400,
return_value=0x0) at /path/to/php-src/Zend/zend_vm_execute.h:67944
#6 0x0000000000b3a5a0 in zend_execute_scripts (type=8, retval=0x0,
file_count=3) at /path/to/php-src/Zend/zend.c:1639
#7 0x0000000000a72dfd in php_execute_script
(primary_file=0x7fffffffc680) at /path/to/php-src/main/main.c:2633
#8 0x0000000000c3fa52 in do_cli (argc=2, argv=0x181f030) at
/path/to/php-src/sapi/cli/php_cli.c:992
#9 0x0000000000c40e9d in main (argc=2, argv=0x181f030) at
/path/to/php-src/sapi/cli/php_cli.c:1384
```
Test script:
---------------
<?php
class X {
public static function main() {
return new class() extends Base {};
}
}
class Base {}
call_user_func(function() {
$base = Base::class;
foreach (get_declared_classes() as $class) {
if (strpos($class, 'class@anonymous') === false) {
continue;
}
echo "Checking for $class\n";
flush();
$rc = new ReflectionClass($class);
var_export($rc->isSubclassOf($base)); // Segfaults on this
line
}
});
Expected result:
----------------
Does not segfault, prints Checking for class@anonymouspath...false (like
earlier php versions do)
Actual result:
--------------
Segfaults because of the call to isSubclassOf
--
Edit bug report at https://bugs.php.net/bug.php?id=77631&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77631&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77631&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77631&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77631&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77631&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77631&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77631&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77631&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77631&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77631&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77631&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77631&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77631&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77631&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77631&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77631&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77631&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77631&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77631&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77631&r=mysqlcfg