php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34216 Segfault with autoload
Submitted: 2005-08-23 07:27 UTC Modified: 2005-11-01 22:03 UTC
From: sebastian@php.net Assigned: helly (profile)
Status: Closed Package: SPL related
PHP Version: 5CVS-2005-09-26 (CVS) OS: *
Private report: No CVE-ID: None
 [2005-08-23 07:27 UTC] sebastian@php.net
Description:
------------
I am experiencing a segfault with spl_autoload in the
PHP_5_1 branch with the upcoming PHPUnit 2.3.0.

The nature of PHPUnit's complexity makes it almost
impossible for me to come up with a simple, reproducing
script (I already invested hours into this, to no avail so
far).

It is weird that the segfault only occurs in one out of
two common code paths of PHPUnit's TextUI test runner.

Furthermore, small code changes (see below) seem to make
the problem go away:

Reproduce code:
---------------
Segfault:

   function PHPUnit2_Util_Classloader($className) {
       print "Loading $className.\n";

       if (strpos($className, 'PHPUnit2_') !== FALSE) {
           @include(str_replace('_', '/', $className) . '.php');
       }
   }

   spl_autoload_register('PHPUnit2_Util_Classloader');

Segfault:

   function PHPUnit2_Util_Classloader($className) {
       $bt = debug_backtrace();
       print "Loading $className.\n";

       if (strpos($className, 'PHPUnit2_') !== FALSE) {
           @include(str_replace('_', '/', $className) . '.php');
       }
   }

   spl_autoload_register('PHPUnit2_Util_Classloader');

No Segfault:

   function PHPUnit2_Util_Classloader($className) {
       $bt = debug_backtrace();
       print_r($bt[1]);
       print "Loading $className.\n";

       if (strpos($className, 'PHPUnit2_') !== FALSE) {
           @include(str_replace('_', '/', $className) . '.php');
       }
   }

   spl_autoload_register('PHPUnit2_Util_Classloader');

Actual result:
--------------
Below are the links to the results of GDB and Valgrind.

Interestingly, when run through GDB it segfaults, when run
through Valgrind it does not segfault.

GDB:
http://www.sebastian-bergmann.de/stuff/phpunit2-gdb.txt
Valgrind:
http://www.sebastian-bergmann.de/stuff/phpunit2-valgrind.txt

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-20 14:56 UTC] tony2001@php.net
Sebastian, I'd appreciate if you provide a complete reproduce case (doesn't matter which size it is).
 [2005-09-21 11:43 UTC] helly@php.net
Can you verify the code with HEAD in non unicode mode?
 [2005-09-21 12:29 UTC] sebastian@php.net
I no longer use auto-loading in PHPUnit2 because of this segfault. I will try a CVS checkout of PHPUnit2 before I abandoned spl_autoload() later, hopefully during the next couple of days.
 [2005-09-26 20:00 UTC] helly@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-09-26 20:57 UTC] sebastian@php.net
Tried with yesterday's CVS of PHP_5_1 and I still get a segfault.
 [2005-10-07 10:36 UTC] sebastian@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 01:01:28 2024 UTC