aports/testing/php84-meminfo/fix-build.patch
2026-03-05 08:13:41 +01:00

87 lines
2.8 KiB
Diff

Patch-Source: https://github.com/BitOne/php-meminfo/pull/139
commit df1e00544587a9d1dbcb70858dbd2e4677424b1c
Author: Andy Postnikov <apostnikov@gmail.com>
Date: Mon Feb 16 02:31:29 2026 +0100
Fix PHP 8.5 compatibility: segfault and IS_UNDEF crashes
Restore EG(current_execute_data) after walking execution frames in
meminfo_browse_exec_frames(), skip IS_UNDEF zvals after IS_INDIRECT
dereferencing, and safely extract object pointer in frame label builder.
Also fix dynamic property deprecation in test for PHP 8.2+.
diff --git a/extension/meminfo.c b/extension/meminfo.c
index b91b5b5..e8f1c51 100644
--- a/meminfo.c
+++ b/meminfo.c
@@ -90,9 +90,11 @@ PHP_FUNCTION(meminfo_dump)
*/
void meminfo_browse_exec_frames(php_stream *stream, HashTable *visited_items, int *first_element)
{
- zend_execute_data *exec_frame, *prev_frame;
+ zend_execute_data *exec_frame;
+ zend_execute_data *original_execute_data;
zend_array *p_symbol_table;
+ original_execute_data = EG(current_execute_data);
exec_frame = EG(current_execute_data);
char frame_label[500];
@@ -122,6 +124,8 @@ void meminfo_browse_exec_frames(php_stream *stream, HashTable *visited_items, i
}
exec_frame = exec_frame->prev_execute_data;
}
+
+ EG(current_execute_data) = original_execute_data;
}
/**
@@ -246,6 +250,11 @@ void meminfo_hash_dump(php_stream *stream, HashTable *ht, zend_bool is_object, H
zval = Z_INDIRECT_P(zval);
}
+ if (Z_TYPE_P(zval) == IS_UNDEF) {
+ zend_hash_move_forward_ex(ht, &pos);
+ continue;
+ }
+
if (Z_ISREF_P(zval)) {
ZVAL_DEREF(zval);
}
@@ -311,6 +320,10 @@ void meminfo_zval_dump(php_stream * stream, char * frame_label, zend_string * sy
zv = Z_INDIRECT_P(zv);
}
+ if (Z_TYPE_P(zv) == IS_UNDEF) {
+ return;
+ }
+
if (Z_ISREF_P(zv)) {
ZVAL_DEREF(zv);
}
@@ -447,7 +460,11 @@ void meminfo_build_frame_label(char* frame_label, int frame_label_len, zend_exec
zend_object *object;
zend_execute_data *ptr;
- object = Z_OBJ(frame->This);
+ if (Z_TYPE(frame->This) == IS_OBJECT) {
+ object = Z_OBJ(frame->This);
+ } else {
+ object = NULL;
+ }
ptr = frame->prev_execute_data;
if (frame->func) {
diff --git a/extension/tests/bug-github-76_children_items_not_linked_php7.phpt b/extension/tests/bug-github-76_children_items_not_linked_php7.phpt
index 676c7e6..12aa37f 100644
--- a/tests/bug-github-76_children_items_not_linked_php7.phpt
+++ b/tests/bug-github-76_children_items_not_linked_php7.phpt
@@ -9,6 +9,7 @@ Check that all children items are properly linked through their identifiers
<?php
$dump = fopen('php://memory', 'rw');
+ #[AllowDynamicProperties]
class MyClass {
public $myDeclaredVar;
}