wardenenv / images

MIT License
6 stars 16 forks source link

ionCube(?) causes bin/magento to segfault when run inside the debug container (PHP 8.1) #35

Open mattijv opened 2 months ago

mattijv commented 2 months ago

Tested with

Steps to reproduce

  1. Initialize a new Warden environment warden env-init, choose magento2 as the type.
  2. Install symfony/console with composer require symfony/console.
  3. Add the test file (below) and enter the debug container.
  4. Run php test.php.

This should result in the following:

www-data@segfault-php-debug:/var/www/html$ php test.php 
Segmentation fault (core dumped)

(Xdebug will complain about not being able to connect, but that does not affect the problem so I omitted it from the output.)

Test file to trigger the issue

<?php

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\CompleteCommand;

require 'vendor/autoload.php';

$attribute = (new \ReflectionClass(CompleteCommand::class))->getAttributes(AsCommand::class);

$attribute[0]->newInstance();

Details

I faced this problem when running the Magento CLI command (bin/magento) and tracked down the problematic lines to \Symfony\Component\Console\Command\Command::getDefaultName (when subclassed as \Symfony\Component\Console\Command\CompleteCommand). The test file is a minimal sample that triggers the issue.

Running the file with gdb reveals the following stack trace after triggering the segfault:

Program received signal SIGSEGV, Segmentation fault.
0x000055f832a87323 in zend_observer_fcall_end ()
(gdb) bt full
#0  0x000055f832a87323 in zend_observer_fcall_end ()
#1  0x000055f832a55519 in execute_ex ()
#2  0x00007fdb459e83f5 in ?? () from /usr/lib64/php/modules/ioncube_loader.so
#3  0x00007fdb459e847b in ?? () from /usr/lib64/php/modules/ioncube_loader.so
#4  0x00007fdb45a8ef0d in ?? () from /usr/lib64/php/modules/ioncube_loader.so
#5  0x00007fdb45a9af70 in ?? () from /usr/lib64/php/modules/ioncube_loader.so
#6  0x00007fdb459a61b3 in ?? () from /usr/lib64/php/modules/ioncube_loader.so
#7  0x00007fdb4592c995 in xdebug_execute_internal () from /usr/lib64/php/modules/xdebug.so
#8  0x000055f832832df4 in ZEND_DO_FCALL_SPEC_OBSERVER_HANDLER ()
#9  0x000055f83283382a in execute_ex[cold] ()
#10 0x00007fdb459e83f5 in ?? () from /usr/lib64/php/modules/ioncube_loader.so
#11 0x00007fdb459e847b in ?? () from /usr/lib64/php/modules/ioncube_loader.so
#12 0x000055f832a5f1d9 in zend_execute ()
#13 0x000055f8329ef250 in zend_execute_scripts ()
#14 0x000055f832989f1a in php_execute_script ()
#15 0x000055f832ad83fe in do_cli ()
#16 0x000055f83283ddeb in main ()

The segmentation fault does not happen if I either

  1. run the sample program from the normal (non-Xdebug) shell, OR
  2. disable the ionCube loaders by commenting out the line in /etc/php.d/01-ioncube-loader.ini.

Thoughts

I'm guessing this is an issue with ionCube and not in the Warden images per se. However, since the images bundle the problematic version, and I can't quickly find an official way to disable it, I'm opening this issue here.

mattijv commented 2 months ago

It appears this does not happen with PHP 8.2 or 8.3.

CSalih commented 1 month ago

Same issue also with PHP 8.2 and 8.3. Disabling ionCube solves the issue.

PHP 8.2.23 (cli) (built: Aug 27 2024 15:32:20) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.23, Copyright (c) Zend Technologies
    with the ionCube PHP Loader v13.3.1, Copyright (c) 2002-2024, by ionCube Ltd.
    with Zend OPcache v8.2.23, Copyright (c), by Zend Technologies
    with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans
PHP 8.3.11 (cli) (built: Aug 27 2024 19:16:34) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.3.11, Copyright (c) Zend Technologies
    with the ionCube PHP Loader v13.3.1, Copyright (c) 2002-2024, by ionCube Ltd.
    with Zend OPcache v8.3.11, Copyright (c), by Zend Technologies
    with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans
navarr commented 1 month ago

@mattijv @CSalih What is your OS and Architecture (x64/aarch64)?

Interestingly, I'm not seeing this on Mac OS X 14.5 aarch64.

www-data@magento-multisite-php-debug:/var/www/html$ php test.php

Warning: Undefined array key 0 in /var/www/html/test.php on line 10

Fatal error: Uncaught Error: Call to a member function newInstance() on null in /var/www/html/test.php:10
Stack trace:
#0 {main}
  thrown in /var/www/html/test.php on line 10
PHP 8.1.29 (cli) (built: Jun  5 2024 05:51:57) (NTS gcc aarch64)
Copyright (c) The PHP Group
Zend Engine v4.1.29, Copyright (c) Zend Technologies
    with the ionCube PHP Loader v13.3.1, Copyright (c) 2002-2024, by ionCube Ltd.
    with Zend OPcache v8.1.29, Copyright (c), by Zend Technologies
    with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans
CSalih commented 1 month ago

@navarr Ubuntu 24 and MacOS 15 both running on x64 architecture. Seems to be an x64 related issue?

mattijv commented 1 month ago
x86_64
Ubuntu 24.04.1 LTS
CSalih commented 1 month ago

@mattijv do you have the latest image? You may run warden env pull && warden env up and it try again?

Edit: For PHP 8.2 and 8.3

mattijv commented 1 month ago

Changed the PHP version in .env to 8.2 and 8.3, and did warden env pull between each test.

www-data@segfault-php-debug:/var/www/html$ php --version
PHP 8.2.23 (cli) (built: Aug 27 2024 15:32:20) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.23, Copyright (c) Zend Technologies
    with the ionCube PHP Loader v13.3.1, Copyright (c) 2002-2024, by ionCube Ltd.
    with Zend OPcache v8.2.23, Copyright (c), by Zend Technologies
    with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans
www-data@segfault-php-debug:/var/www/html$ php test.php 
[snip xdebug warning]
www-data@segfault-php-debug:/var/www/html$ 
www-data@segfault-php-debug:/var/www/html$ php --version
PHP 8.3.11 (cli) (built: Aug 27 2024 19:16:34) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.3.11, Copyright (c) Zend Technologies
    with the ionCube PHP Loader v13.3.1, Copyright (c) 2002-2024, by ionCube Ltd.
    with Zend OPcache v8.3.11, Copyright (c), by Zend Technologies
    with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans
www-data@segfault-php-debug:/var/www/html$ php test.php 
[snip xdebug warning]
www-data@segfault-php-debug:/var/www/html$ 

No errors (beside the xdebug warnings).

Went back to 8.1:

www-data@segfault-php-debug:/var/www/html$ php --version
PHP 8.1.29 (cli) (built: Jun  5 2024 05:51:57) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.29, Copyright (c) Zend Technologies
    with the ionCube PHP Loader v13.3.1, Copyright (c) 2002-2024, by ionCube Ltd.
    with Zend OPcache v8.1.29, Copyright (c), by Zend Technologies
    with Xdebug v3.3.2, Copyright (c) 2002-2024, by Derick Rethans
www-data@segfault-php-debug:/var/www/html$ php test.php 
[snip xdebug warning]
Segmentation fault (core dumped)
www-data@segfault-php-debug:/var/www/html$