php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62904 Crash when cloning an object which inherits SplFixedArray
Submitted: 2012-08-23 12:30 UTC Modified: 2012-08-23 15:19 UTC
From: felipe@php.net Assigned: laruence (profile)
Status: Closed Package: SPL related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2012-08-23 12:30 UTC] felipe@php.net
Description:
------------
See below.

Test script:
---------------
<?php

class foo extends SplFixedArray {       
        public function __construct() { }
}

$x = new foo;

try {
        $z = clone $x;
} catch (Exception $e) {
        var_dump($e->getMessage());
}


Actual result:
--------------
Program received signal SIGSEGV, Segmentation fault.
0x082fc564 in spl_fixedarray_object_new_ex (class_type=0xb6a06f74, obj=0xbfffbf08, orig=0xb6a05964, clone_orig=1, tsrm_ls=0x8942050)
    at /home/felipe/dev/php-src/ext/spl/spl_fixedarray.c:228
228			spl_fixedarray_init(intern->array, other->array->size TSRMLS_CC);
(gdb) p other->array
$6 = (spl_fixedarray *) 0x0


Patches

Fixed-bug-62904-Crash-when-cloning-an-object (last revision 2012-08-23 14:39 UTC by reeze dot xia at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-23 12:37 UTC] felipe@php.net
-Summary: Crash when cloning an object wich inherits SplFixedArray +Summary: Crash when cloning an object which inherits SplFixedArray
 [2012-08-23 14:46 UTC] reeze dot xia at gmail dot com
when construct a object but didn't call the parent constructor.

this patch makes it construct as default.

We could also throw an exception here too, but other method didn't 
checked the situation of SplFixArray::__construct didn't get called.
so I think we could makes them consist.
 [2012-08-23 14:48 UTC] reeze dot xia at gmail dot com
"but other method didn't check"  I mean *did* :)
 [2012-08-23 15:18 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=42f91d6ac6e4c359313ddc90b86067ab9be6a80f
Log: Fixed bug #62904 (Crash when cloning an object which inherits SplFixedArray)
 [2012-08-23 15:19 UTC] laruence@php.net
This bug has been fixed in SVN.

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/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-08-23 15:19 UTC] laruence@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: laruence
 [2012-08-23 15:24 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=13bcf685cb0a92e502ebe39f4b22c64304a9f333
Log: Fixed bug #62904 (Crash when cloning an object which inherits SplFixedArray)
 [2012-08-23 15:25 UTC] reeze dot xia at gmail dot com
I really don't think throw an exception is a good idea.

Think about this:

<?php

class foo extends SplFixedArray {       
        public function __construct() { }
}

$x = new foo;

$x->setSize(1);
$x[0] = 30;
var_dump($x);
?>

This works.
if you throw an exception when clone.
$x->setSize(0) should throw too. since it was not initialized properly.
 [2012-08-23 15:25 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=13bcf685cb0a92e502ebe39f4b22c64304a9f333
Log: Fixed bug #62904 (Crash when cloning an object which inherits SplFixedArray)
 [2012-08-23 15:25 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=13bcf685cb0a92e502ebe39f4b22c64304a9f333
Log: Fixed bug #62904 (Crash when cloning an object which inherits SplFixedArray)
 [2012-08-23 15:25 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=42f91d6ac6e4c359313ddc90b86067ab9be6a80f
Log: Fixed bug #62904 (Crash when cloning an object which inherits SplFixedArray)
 [2014-10-07 23:22 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=13bcf685cb0a92e502ebe39f4b22c64304a9f333
Log: Fixed bug #62904 (Crash when cloning an object which inherits SplFixedArray)
 [2014-10-07 23:22 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=42f91d6ac6e4c359313ddc90b86067ab9be6a80f
Log: Fixed bug #62904 (Crash when cloning an object which inherits SplFixedArray)
 [2014-10-07 23:33 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=13bcf685cb0a92e502ebe39f4b22c64304a9f333
Log: Fixed bug #62904 (Crash when cloning an object which inherits SplFixedArray)
 [2014-10-07 23:33 UTC] stas@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=42f91d6ac6e4c359313ddc90b86067ab9be6a80f
Log: Fixed bug #62904 (Crash when cloning an object which inherits SplFixedArray)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 04:01:28 2024 UTC