Skip to content

Fix create_object checks #13272

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
wants to merge 1 commit into from
Closed
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
26 changes: 20 additions & 6 deletions Zend/Optimizer/escape_analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,17 @@ static bool is_allocation_def(zend_op_array *op_array, zend_ssa *ssa, int def, i
/* These flags will always cause an exception */
ZEND_ACC_IMPLICIT_ABSTRACT_CLASS | ZEND_ACC_EXPLICIT_ABSTRACT_CLASS
| ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT;
if (ce && !ce->parent && !ce->create_object && !ce->constructor &&
!ce->destructor && !ce->__get && !ce->__set &&
!(ce->ce_flags & forbidden_flags) &&
(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
if (ce
&& !ce->parent
&& !ce->create_object
&& ce->default_object_handlers->get_constructor == zend_std_get_constructor
&& ce->default_object_handlers->dtor_obj == zend_objects_destroy_object
&& !ce->constructor
&& !ce->destructor
&& !ce->__get
&& !ce->__set
&& !(ce->ce_flags & forbidden_flags)
&& (ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
return 1;
}
break;
Expand Down Expand Up @@ -227,8 +234,15 @@ static bool is_local_def(zend_op_array *op_array, zend_ssa *ssa, int def, int va
/* objects with destructors should escape */
zend_class_entry *ce = zend_optimizer_get_class_entry_from_op1(
script, op_array, opline);
if (ce && !ce->create_object && !ce->constructor &&
!ce->destructor && !ce->__get && !ce->__set && !ce->parent) {
if (ce
&& !ce->create_object
&& ce->default_object_handlers->get_constructor == zend_std_get_constructor
&& ce->default_object_handlers->dtor_obj == zend_objects_destroy_object
&& !ce->constructor
&& !ce->destructor
&& !ce->__get
&& !ce->__set
&& !ce->parent) {
return 1;
}
break;
Expand Down
10 changes: 8 additions & 2 deletions Zend/Optimizer/zend_inference.c
Original file line number Diff line number Diff line change
Expand Up @@ -3776,6 +3776,7 @@ static zend_always_inline zend_result _zend_update_type_info(
/* Unset properties will resort back to __get/__set */
if (ce
&& !ce->create_object
&& ce->default_object_handlers->read_property == zend_std_read_property
&& !ce->__get
&& !result_may_be_separated(ssa, ssa_op)) {
tmp &= ~MAY_BE_RC1;
Expand Down Expand Up @@ -5069,8 +5070,13 @@ ZEND_API bool zend_may_throw_ex(const zend_op *opline, const zend_ssa_op *ssa_op
const zend_ssa_var_info *var_info = ssa->var_info + ssa_op->op1_use;
const zend_class_entry *ce = var_info->ce;

if (var_info->is_instanceof ||
!ce || ce->create_object || ce->__get || ce->__set || ce->parent) {
if (var_info->is_instanceof
|| !ce
|| ce->create_object
|| ce->default_object_handlers->write_property != zend_std_write_property
|| ce->__get
|| ce->__set
|| ce->parent) {
Copy link
Member

Choose a reason for hiding this comment

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

get_property_ptr_ptr should be checked as well.

Everything else looks right.

Copy link
Member Author

Choose a reason for hiding this comment

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

Of course, thanks!

return 1;
}

Expand Down