[php-src] PR #14105: Delay #[Attribute] arg validation until runtime
| From: | iluuu1994 | Date: | Wed, 01 May 2024 16:58:26 +0000 |
| Subject: | [php-src] PR #14105: Delay #[Attribute] arg validation until runtime | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-25980@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/14105
Author: iluuu1994
We cannot validate at compmile-time for multiple reasons:
* Enums cannot be instantiated at runtime (the actual bug report).
* Evaluating the argument naively with zend_get_attribute_value can lead to code execution at
runtime through the new expression, leading to reentrance of the compiler.
* Even if the evaluation was possible, it would need to be restricted to the current file, because
constant values coming from other files can change without affecting the current compilation unit.
For this reason, validation would need to be repeated at runtime anyway.
Instead, we just move it to runtime entirely. It's only needed for
ReflectionAttribute::newInstance(), which is not particularly a hot path. The checks are also
simple.