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: [email protected] 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] [email protected]
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

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-20 14:56 UTC] [email protected]
Sebastian, I'd appreciate if you provide a complete reproduce case (doesn't matter which size it is).
 [2005-09-21 11:43 UTC] [email protected]
Can you verify the code with HEAD in non unicode mode?
 [2005-09-21 12:29 UTC] [email protected]
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:57 UTC] [email protected]
Tried with yesterday's CVS of PHP_5_1 and I still get a segfault.
 [2005-10-07 10:36 UTC] [email protected]
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-2025 The PHP Group
All rights reserved.
Last updated: Wed Dec 31 05:00:01 2025 UTC