tideways / php-xhprof-extension

This XHProf PHP extension fork has outlived its purpose and is archived in favor of the revitalized https://github.com/longxinH/xhprof
https://tideways.com
Apache License 2.0
1.64k stars 209 forks source link

Tideways makes PHP 8.1.12 with ioncube loader crash #117

Closed nradchenko closed 2 years ago

nradchenko commented 2 years ago

I can't get PHP 8.1 with recently released Ioncube loader to process encoded files.

The test file is just a single echo line encoded with latest Ioncube PHP Encoder 12 (free trial version).

 $ cat test.php
<?php
echo "there's nothing to cause segmentation fault here\n";
 $ ../ioncube_encoder_evaluation/ioncube_encoder.sh -C -x86-64 -81 test.php -o test.encoded.php                                                                               
 $ 

Current PHP (php:8.1.12-cli from Docker Hub) runs the script fine, but when I tell PHP to load tideways this results in a reproducible crash.

root@076fafe6d25f:~# php -v
PHP 8.1.12 (cli) (built: Nov 15 2022 04:42:55) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.12, Copyright (c) Zend Technologies
root@076fafe6d25f:~# php -n -dzend_extension=/test/ioncube_loader_lin_8.1.so -dextension=/test/php-xhprof-extension-master/.libs/tideways_xhprof.so -v
PHP 8.1.12 (cli) (built: Nov 15 2022 04:42:55) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.12, Copyright (c) Zend Technologies
    with the ionCube PHP Loader v12.0.2, Copyright (c) 2002-2022, by ionCube Ltd.
root@076fafe6d25f:~# php -n -dzend_extension=/test/ioncube_loader_lin_8.1.so /test/test.encoded.php 
there's nothing to cause segmentation fault here
root@076fafe6d25f:~# php -n -dzend_extension=/test/ioncube_loader_lin_8.1.so -dextension=/test/php-xhprof-extension-master/.libs/tideways_xhprof.so /test/test.encoded.php 
Segmentation fault (core dumped)
root@076fafe6d25f:~# 
(gdb) r
Starting program: /usr/local/bin/php -n -dzend_extension=/test/ioncube_loader_lin_8.1.so -dextension=/test/php-xhprof-extension-master/.libs/tideways_xhprof.so /test/test.encoded.php
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff4801040 in ?? ()
(gdb) bt
#0  0x00007ffff4801040 in ?? ()
#1  0x0000555555b13819 in ?? ()
#2  0x0000555555aebe73 in zend_execute ()
#3  0x0000555555a7f35d in zend_execute_scripts ()
#4  0x0000555555a1b481 in php_execute_script ()
#5  0x0000555555b60191 in ?? ()
#6  0x0000555555798ca1 in ?? ()
#7  0x00007ffff7483d0a in __libc_start_main (main=0x5555557988d0, argc=5, argv=0x7fffffffe988, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffe978)
    at ../csu/libc-start.c:308
#8  0x000055555579943a in _start ()
(gdb)  

Another backtrace of a custom PHP build (8.1.12 too):

Program received signal SIGSEGV, Segmentation fault.
0x00007fff00000001 in ?? ()
(gdb) bt
#0  0x00007fff00000001 in ?? ()
#1  0x0000555555a69e71 in _zend_observe_fcall_begin (execute_data=0x7ffff6a14020) at /build/tmp-build/php-src-tag-beget-version-8.1.12-1/Zend/zend_observer.c:170
#2  0x0000555555a6a135 in zend_observer_fcall_begin (execute_data=execute_data@entry=0x7ffff6a14020) at /build/tmp-build/php-src-tag-beget-version-8.1.12-1/Zend/zend_observer.c:183
#3  0x0000555555a42263 in zend_execute (op_array=0x7ffff6a9d000, return_value=0x0) at /build/tmp-build/php-src-tag-beget-version-8.1.12-1/Zend/zend_vm_execute.h:60145
#4  0x00005555559d37b0 in zend_execute_scripts (type=type@entry=8, retval=retval@entry=0x0, file_count=file_count@entry=3) at /build/tmp-build/php-src-tag-beget-version-8.1.12-1/Zend/zend.c:1799
#5  0x000055555596ecfa in php_execute_script (primary_file=primary_file@entry=0x7fffffffd4a0) at /build/tmp-build/php-src-tag-beget-version-8.1.12-1/main/main.c:2541
#6  0x0000555555ab7e1e in do_cli (argc=5, argv=0x5555564aeae0) at /build/tmp-build/php-src-tag-beget-version-8.1.12-1/sapi/cli/php_cli.c:965
#7  0x00005555556e47b7 in main (argc=5, argv=0x5555564aeae0) at /build/tmp-build/php-src-tag-beget-version-8.1.12-1/sapi/cli/php_cli.c:1367
(gdb) 
beberlei commented 2 years ago

This is a known issue with ioncube loader, other extensions using observers would also crash. Please talk to the Ioncube support.

nradchenko commented 2 years ago

Thanks @beberlei , looks like you're right - I've tried another extension that utilizes observers API and got a segfault too. So the problem parts are observers and Ioncube loader, not tideways.

If this is a known problem, could you point me to a relevant discussion which explains why the error happens and what probably might go wrong in Ioncube? I guess it somehow violates Zend API which makes the whole thing crash.

beberlei commented 2 years ago

@nradchenko You have to talk to ioncube support, I had a support ticket from one of our customers regarding this issue a few weeks ago, its not a public discussion and I havent seen a public discussion on ioncube webseite either.

nradchenko commented 2 years ago

OK, thanks for info!