Skip to content

GH-22354: support interfaces added by attribute validators in zend_compile_implements()#22355

Open
DanielEScherzer wants to merge 2 commits into
php:PHP-8.4from
DanielEScherzer:attribute-validator-interfaces
Open

GH-22354: support interfaces added by attribute validators in zend_compile_implements()#22355
DanielEScherzer wants to merge 2 commits into
php:PHP-8.4from
DanielEScherzer:attribute-validator-interfaces

Conversation

@DanielEScherzer

Copy link
Copy Markdown
Member

No description provided.

Comment thread ext/zend_test/test.c Outdated

zend_class_name *newInterfaceSet = erealloc(
scope->interface_names,
sizeof(zend_class_name) * scope->num_interfaces

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.

Multiplication for allocations is unsafe. You need one of the _safe variants. The sizeof(zend_class_name) should also be sizeof(*newInterfaceSet).

Same for the allocations in zend_compile.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done, though at least in zend_compile this was matching existing multiplications

In `zend_compile_implements()`, when there were no interfaces already added,
keep the existing code of just adding the newly declared interfaces. But, when
some interfaces are already present, don't overwrite them. Instead, add to the
existing list.

In case the developer tries to add an interface that was already added by an
attribute, skip the manual interface addition to avoid errors about trying to
apply the same interface multiple times. But, only skip the *first* manual
interface addition of the same interface, if there are multiple such additions
then there really was an attempt to apply the same interface multiple times.

Fixes php#22354
@DanielEScherzer DanielEScherzer force-pushed the attribute-validator-interfaces branch from a911024 to 094b72f Compare June 17, 2026 21:41
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.

zend_compile_implements() assumes that the class entry has no interfaces already

2 participants