Skip to content

Commit d8862f9

Browse files
committed
GH-18572: infinite stack recursion in fallback object comparison.
With nested objects and recursive comparisons, it is for now unavoidable to have a stack overflow we do some early damage control attempt early on with zend.max_allowed_stack_size check but ultimately more a band-aid than a definitive solution.
1 parent 8e5b312 commit d8862f9

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Zend/zend_object_handlers.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@
4242
#define IN_UNSET ZEND_GUARD_PROPERTY_UNSET
4343
#define IN_ISSET ZEND_GUARD_PROPERTY_ISSET
4444

45+
static zend_always_inline bool zend_objects_check_stack_limit(void)
46+
{
47+
#ifdef ZEND_CHECK_STACK_LIMIT
48+
return zend_call_stack_overflowed(EG(stack_limit));
49+
#else
50+
return false;
51+
#endif
52+
}
53+
4554
/*
4655
__X accessors explanation:
4756
@@ -1714,6 +1723,11 @@ ZEND_API int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
17141723
{
17151724
zend_object *zobj1, *zobj2;
17161725

1726+
if (zend_objects_check_stack_limit()) {
1727+
zend_throw_error(NULL, "Object compare - stack limit reached");
1728+
return ZEND_UNCOMPARABLE;
1729+
}
1730+
17171731
if (Z_TYPE_P(o1) != Z_TYPE_P(o2)) {
17181732
/* Object and non-object */
17191733
zval *object;

0 commit comments

Comments
 (0)