projects/aports·blob master · refs

86 lines · 2.8 KiB

1Patch-Source: https://github.com/BitOne/php-meminfo/pull/139
2commit df1e00544587a9d1dbcb70858dbd2e4677424b1c
3Author: Andy Postnikov <[email protected]>
4Date: Mon Feb 16 02:31:29 2026 +0100
5
6 Fix PHP 8.5 compatibility: segfault and IS_UNDEF crashes
7
8 Restore EG(current_execute_data) after walking execution frames in
9 meminfo_browse_exec_frames(), skip IS_UNDEF zvals after IS_INDIRECT
10 dereferencing, and safely extract object pointer in frame label builder.
11 Also fix dynamic property deprecation in test for PHP 8.2+.
12
13diff --git a/extension/meminfo.c b/extension/meminfo.c
14index b91b5b5..e8f1c51 100644
15--- a/meminfo.c
16+++ b/meminfo.c
17@@ -90,9 +90,11 @@ PHP_FUNCTION(meminfo_dump)
18 */
19 void meminfo_browse_exec_frames(php_stream *stream, HashTable *visited_items, int *first_element)
20 {
21- zend_execute_data *exec_frame, *prev_frame;
22+ zend_execute_data *exec_frame;
23+ zend_execute_data *original_execute_data;
24 zend_array *p_symbol_table;
25
26+ original_execute_data = EG(current_execute_data);
27 exec_frame = EG(current_execute_data);
28
29 char frame_label[500];
30@@ -122,6 +124,8 @@ void meminfo_browse_exec_frames(php_stream *stream, HashTable *visited_items, i
31 }
32 exec_frame = exec_frame->prev_execute_data;
33 }
34+
35+ EG(current_execute_data) = original_execute_data;
36 }
37
38 /**
39@@ -246,6 +250,11 @@ void meminfo_hash_dump(php_stream *stream, HashTable *ht, zend_bool is_object, H
40 zval = Z_INDIRECT_P(zval);
41 }
42
43+ if (Z_TYPE_P(zval) == IS_UNDEF) {
44+ zend_hash_move_forward_ex(ht, &pos);
45+ continue;
46+ }
47+
48 if (Z_ISREF_P(zval)) {
49 ZVAL_DEREF(zval);
50 }
51@@ -311,6 +320,10 @@ void meminfo_zval_dump(php_stream * stream, char * frame_label, zend_string * sy
52 zv = Z_INDIRECT_P(zv);
53 }
54
55+ if (Z_TYPE_P(zv) == IS_UNDEF) {
56+ return;
57+ }
58+
59 if (Z_ISREF_P(zv)) {
60 ZVAL_DEREF(zv);
61 }
62@@ -447,7 +460,11 @@ void meminfo_build_frame_label(char* frame_label, int frame_label_len, zend_exec
63 zend_object *object;
64 zend_execute_data *ptr;
65
66- object = Z_OBJ(frame->This);
67+ if (Z_TYPE(frame->This) == IS_OBJECT) {
68+ object = Z_OBJ(frame->This);
69+ } else {
70+ object = NULL;
71+ }
72 ptr = frame->prev_execute_data;
73
74 if (frame->func) {
75diff --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
76index 676c7e6..12aa37f 100644
77--- a/tests/bug-github-76_children_items_not_linked_php7.phpt
78+++ b/tests/bug-github-76_children_items_not_linked_php7.phpt
79@@ -9,6 +9,7 @@ Check that all children items are properly linked through their identifiers
80 <?php
81 $dump = fopen('php://memory', 'rw');
82
83+ #[AllowDynamicProperties]
84 class MyClass {
85 public $myDeclaredVar;
86 }