Skip to content

Fix GH-25149: Leak of class constant type names in uncached classes - #25151

Open
lazerg wants to merge 2 commits into
php:PHP-8.4from
lazerg:fix/gh-25149-nullable-const-type-leak
Open

lazerg wants to merge 2 commits into
php:PHP-8.4from
lazerg:fix/gh-25149-nullable-const-type-leak

Conversation

@lazerg

@lazerg lazerg commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

destroy_zend_class() never released the type of user class constants. Without opcache the class names in those types are interned, so nothing showed up, but with opcache they stay refcounted until persistence, and any class that isn't cached (eval'd code, the parser fuzzer) leaks them. The type is now released for constants the class owns, same as property types. Inherited CONST_OWNED copies are skipped since they share the parent's type.

Trait constants and constants of lazy loaded classes are copied with ce set to the new class, so their type is now deep copied the same way property types are. Otherwise the new release would free a type the class doesn't own.

Fixes #25149

@iliaal iliaal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for the fix. Please squash the two commits into one: the first on its own releases constant types that trait and lazy-loaded copies still share with the source class, which ends in a use-after-free.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants