Skip to content

Fix GH-18567: Preloading with internal class alias triggers assertion failure #18575

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

Open
wants to merge 1 commit into
base: PHP-8.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -3522,7 +3522,7 @@ static void preload_shutdown(void)
if (EG(class_table)) {
ZEND_HASH_MAP_REVERSE_FOREACH_VAL(EG(class_table), zv) {
zend_class_entry *ce = Z_PTR_P(zv);
if (ce->type == ZEND_INTERNAL_CLASS) {
if (ce->type == ZEND_INTERNAL_CLASS && Z_TYPE_P(zv) != IS_ALIAS_PTR) {
break;
}
} ZEND_HASH_MAP_FOREACH_END_DEL();
Expand Down Expand Up @@ -3610,7 +3610,15 @@ static void preload_move_user_classes(HashTable *src, HashTable *dst)
zend_hash_extend(dst, dst->nNumUsed + src->nNumUsed, 0);
ZEND_HASH_MAP_FOREACH_BUCKET_FROM(src, p, EG(persistent_classes_count)) {
zend_class_entry *ce = Z_PTR(p->val);
ZEND_ASSERT(ce->type == ZEND_USER_CLASS);

/* Possible with internal class aliases */
if (ce->type == ZEND_INTERNAL_CLASS) {
ZEND_ASSERT(Z_TYPE(p->val) == IS_ALIAS_PTR);
_zend_hash_append(dst, p->key, &p->val);
zend_hash_del_bucket(src, p);
continue;
}

if (ce->info.user.filename != filename) {
filename = ce->info.user.filename;
if (filename) {
Expand Down Expand Up @@ -3904,7 +3912,12 @@ static void preload_link(void)

ZEND_HASH_MAP_FOREACH_STR_KEY_VAL_FROM(EG(class_table), key, zv, EG(persistent_classes_count)) {
ce = Z_PTR_P(zv);
ZEND_ASSERT(ce->type != ZEND_INTERNAL_CLASS);

/* Possible with internal class aliases */
if (ce->type == ZEND_INTERNAL_CLASS) {
ZEND_ASSERT(Z_TYPE_P(zv) == IS_ALIAS_PTR);
continue;
}

if (!(ce->ce_flags & (ZEND_ACC_TOP_LEVEL|ZEND_ACC_ANON_CLASS))
|| (ce->ce_flags & ZEND_ACC_LINKED)) {
Expand Down Expand Up @@ -3990,9 +4003,15 @@ static void preload_link(void)

ZEND_HASH_MAP_REVERSE_FOREACH_VAL(EG(class_table), zv) {
ce = Z_PTR_P(zv);

/* Possible with internal class aliases */
if (ce->type == ZEND_INTERNAL_CLASS) {
break;
if (Z_TYPE_P(zv) != IS_ALIAS_PTR) {
break; /* can stop already */
}
continue;
}

if ((ce->ce_flags & ZEND_ACC_LINKED) && !(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
if (!(ce->ce_flags & ZEND_ACC_TRAIT)) { /* don't update traits */
CG(in_compilation) = true; /* prevent autoloading */
Expand All @@ -4009,7 +4028,13 @@ static void preload_link(void)
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL_FROM(
EG(class_table), key, zv, EG(persistent_classes_count)) {
ce = Z_PTR_P(zv);
ZEND_ASSERT(ce->type != ZEND_INTERNAL_CLASS);

/* Possible with internal class aliases */
if (ce->type == ZEND_INTERNAL_CLASS) {
ZEND_ASSERT(Z_TYPE_P(zv) == IS_ALIAS_PTR);
continue;
}

if ((ce->ce_flags & (ZEND_ACC_TOP_LEVEL|ZEND_ACC_ANON_CLASS))
&& !(ce->ce_flags & ZEND_ACC_LINKED)) {
zend_string *lcname = zend_string_tolower(ce->name);
Expand Down
27 changes: 27 additions & 0 deletions ext/opcache/tests/gh18567.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
GH-18567 (Preloading with internal class alias triggers assertion failure)
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.preload={PWD}/preload_gh18567.inc
--EXTENSIONS--
opcache
--SKIPIF--
<?php
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
?>
--FILE--
<?php
abstract class Test implements MyStringable {
}
$rc = new ReflectionClass(Test::class);
var_dump($rc->getInterfaces());
?>
--EXPECT--
array(1) {
["Stringable"]=>
object(ReflectionClass)#2 (1) {
["name"]=>
string(10) "Stringable"
}
}
2 changes: 2 additions & 0 deletions ext/opcache/tests/preload_gh18567.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
class_alias('Stringable', 'MyStringable');
Loading