Skip to content

Assertion failure in ext/reflection/php_reflection.c:487 #16187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
YuanchengJiang opened this issue Oct 3, 2024 · 3 comments
Closed

Assertion failure in ext/reflection/php_reflection.c:487 #16187

YuanchengJiang opened this issue Oct 3, 2024 · 3 comments

Comments

@YuanchengJiang
Copy link

Description

The following code:

<?php
$xml = <<<XML
<form name="test"></form>
XML;
$simplexml = simplexml_load_string($xml);
$reflector = new ReflectionObject($simplexml['name']);
$fusion = $reflector;
$file_path = __DIR__;
$filename = "/dev/null";
$octal_formats = array( "%o",);
$file_handle = fopen($filename, "r");
foreach($octal_formats as $octal_format) {
while( !feof($file_handle) ) {
try {
var_dump(fscanf($file_handle,$fusion));
} catch (ValueError $exception) {
}
}
}

Resulted in this output:

/php-src/ext/reflection/php_reflection.c:487: void _class_string(smart_str *, zend_class_entry *, zval *, const char *): Assertion `!(((__ht)->u.flags & (1<<2)) != 0)' failed.
Aborted (core dumped)

PHP Version

PHP 8.4.0-dev

Operating System

ubuntu 22.04

@DanielEScherzer
Copy link
Member

Minimal reproduction:

<?php
$xml = '<form name="test"></form>';
$simplexml = simplexml_load_string($xml);
$reflector = new ReflectionObject($simplexml['name']);
$reflector->__toString();

produces

root@3acd01cef279:/usr/src/php# php /var/www/html/test.php 
php: /usr/src/php/ext/reflection/php_reflection.c:487: _class_string: Assertion `!(((__ht)->u.flags & (1<<2)) != 0)' failed.
Aborted

@DanielEScherzer
Copy link
Member

The assertion comes from a series of macros, ZEND_HASH_MAP_FOREACH_STR_KEY -> ZEND_HASH_MAP_FOREACH -> ZEND_HASH_MAP_FOREACH_FROM -> ZEND_ASSERT(!HT_IS_PACKED(__ht));
Use ZEND_HASH_FOREACH_STR_KEY instead of the map version is enough to fix this

DanielEScherzer added a commit to DanielEScherzer/php-src that referenced this issue Oct 3, 2024
@DanielEScherzer
Copy link
Member

PR is at #16192, I confirmed that it also fixes the reported code (now results in the output bool(false))

DanielEScherzer added a commit to DanielEScherzer/php-src that referenced this issue Oct 4, 2024
DanielEScherzer added a commit to DanielEScherzer/php-src that referenced this issue Oct 4, 2024
nielsdos added a commit that referenced this issue Oct 5, 2024
* PHP-8.4:
  Fix GH-16187: ReflectionClass::__toString() with packed properties hash table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants