Skip to content

Fix GH-17866: zend_mm_heap corrupted error after upgrading from 8.4.3 to 8.4.4 #17880

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 5 commits into from

Conversation

nielsdos
Copy link
Member

This regressed in GH-17592.
The function is with its attributes HashTable* is copied in zend_get_closure_invoke_method() but its refcount is not increased. This caused a crash in the Symfony demo page.

…4.3 to 8.4.4

This regressed in phpGH-17592.
The function is with its attributes HashTable* is copied in
zend_get_closure_invoke_method() but its refcount is not increased.
This caused a crash in the Symfony demo page.
@nielsdos nielsdos marked this pull request as ready for review February 21, 2025 20:53
@nielsdos nielsdos requested a review from dstogov as a code owner February 21, 2025 20:53
@nielsdos nielsdos requested a review from TimWolla February 21, 2025 20:53
@nielsdos
Copy link
Member Author

@dstogov While reviewing #17914 I started wondering why we need to refcount the attributes on trampolines in the first place. The attributes always come from a real function created by the compiler. So it seems to me that the real function, with its attributes, always lives longer than the trampoline.
This means we could skip the refcounting, it would save some operations and also replace this PR with this patch:

diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c
index 277430ce102..efcb7fd5ed3 100644
--- a/Zend/zend_object_handlers.c
+++ b/Zend/zend_object_handlers.c
@@ -1618,12 +1618,7 @@ ZEND_API zend_function *zend_get_call_trampoline_func(const zend_class_entry *ce
 		| ZEND_ACC_PUBLIC
 		| ZEND_ACC_VARIADIC
 		| (fbc->common.fn_flags & (ZEND_ACC_RETURN_REFERENCE|ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED));
-	if (fbc->common.attributes) {
-		func->attributes = fbc->common.attributes;
-		GC_TRY_ADDREF(func->attributes);
-	} else {
-		func->attributes = NULL;
-	}
+	func->attributes = fbc->common.attributes;
 	if (is_static) {
 		func->fn_flags |= ZEND_ACC_STATIC;
 	}
diff --git a/Zend/zend_object_handlers.h b/Zend/zend_object_handlers.h
index 2fc59d5020c..c7348a74245 100644
--- a/Zend/zend_object_handlers.h
+++ b/Zend/zend_object_handlers.h
@@ -339,10 +339,6 @@ ZEND_API bool ZEND_FASTCALL zend_asymmetric_property_has_set_access(const zend_p
 } while (0)
 
 #define zend_free_trampoline(func) do { \
-		HashTable *attributes = (func)->common.attributes; \
-		if (attributes && !(GC_FLAGS(attributes) & GC_IMMUTABLE) && !GC_DELREF(attributes)) { \
-			zend_array_destroy(attributes); \
-		} \
 		if ((func) == &EG(trampoline)) { \
 			EG(trampoline).common.attributes = NULL; \
 			EG(trampoline).common.function_name = NULL; \

The code becomes a bit simpler.
Maybe I miss something however, what do you think? Sorry for the double review effort...

@dstogov
Copy link
Member

dstogov commented Feb 24, 2025

While reviewing #17914 I started wondering why we need to refcount the attributes on trampolines in the first place

I think, you are right. We also don't increment reference-counter of filename, and this never made problems.

@nielsdos nielsdos closed this in 2542357 Feb 24, 2025
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_mm_heap corrupted error after upgrading from 8.4.3 to 8.4.4
3 participants