BitOne / php-meminfo

PHP extension to get insight about memory usage
MIT License
1.08k stars 78 forks source link

GITHUB-108: do not browse non existent symbol tables #109

Closed ahocquard closed 3 years ago

ahocquard commented 3 years ago

See https://github.com/BitOne/php-meminfo/issues/108

Context

The fix https://github.com/BitOne/php-meminfo/pull/106 fixed an issue with a wrong frame name because the symbol table returned by the function zend_rebuild_symbol_table does not necessary return the symbol table of the current zend_execute_data.

The fix is correct but, since PHP 7.4, it is also the cause of a segfault.

Behavior in PHP 7.2/7.3

The symbol table of the current zend_execute_data can be the symbol table of:

In any case, and even before the rebuild of the symbol table, the symbol table is initialized with an empty zend_array.

Therefore, it's possible to browse the symbol table of any frame, even meminfo_dump. It does not make sense to browse this frame as it's not a "user" function though. With the fix in #106., this frame meminfo_dump is browsed.

Behavior in PHP 7.4

The symbol table is never initialized for:

Also, the symbol table is not initialized in a function except if:

Therefore, when meminfo_dump frame is browsed, it tries to iterate over an uninitialized array.

Fix

A possible solution would be to not browse frame that are not "user" function like it's done here: https://github.com/php/php-src/blob/php-7.4.13/Zend/zend_execute_API.c#L1476

But I prefered to only browse a frame corresponding to the rebuilt frame: