Skip to content

Commit 13bcf68

Browse files
committed
Fixed bug #62904 (Crash when cloning an object which inherits SplFixedArray)
1 parent eca4fc6 commit 13bcf68

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ PHP NEWS
3939
. Fixed bug (segfault due to retval is not initialized). (Laruence)
4040

4141
- SPL:
42+
. Fixed bug #62904 (Crash when cloning an object which inherits SplFixedArray)
43+
(Laruence)
4244
. Fixed bug #62616 (ArrayIterator::count() from IteratorIterator instance
4345
gives Segmentation fault). (Laruence, Gustavo)
4446

ext/spl/spl_fixedarray.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,14 @@ static zend_object_value spl_fixedarray_object_new_ex(zend_class_entry *class_ty
223223
if (orig && clone_orig) {
224224
spl_fixedarray_object *other = (spl_fixedarray_object*)zend_object_store_get_object(orig TSRMLS_CC);
225225
intern->ce_get_iterator = other->ce_get_iterator;
226-
227-
intern->array = emalloc(sizeof(spl_fixedarray));
228-
spl_fixedarray_init(intern->array, other->array->size TSRMLS_CC);
229-
spl_fixedarray_copy(intern->array, other->array TSRMLS_CC);
226+
if (!other->array) {
227+
/* leave a empty object, will be dtor later by CLONE handler */
228+
zend_throw_exception(spl_ce_RuntimeException, "The instance wasn't initialized properly", 0 TSRMLS_CC);
229+
} else {
230+
intern->array = emalloc(sizeof(spl_fixedarray));
231+
spl_fixedarray_init(intern->array, other->array->size TSRMLS_CC);
232+
spl_fixedarray_copy(intern->array, other->array TSRMLS_CC);
233+
}
230234
}
231235

232236
while (parent) {

ext/spl/tests/bug62904.phpt

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #62904 (Crash when cloning an object which inherits SplFixedArray)
3+
--FILE--
4+
<?php
5+
6+
class foo extends SplFixedArray {
7+
public function __construct($size) {
8+
}
9+
}
10+
11+
$x = new foo(2);
12+
13+
try {
14+
$z = clone $x;
15+
} catch (Exception $e) {
16+
var_dump($e->getMessage());
17+
}
18+
--EXPECTF--
19+
string(40) "The instance wasn't initialized properly"

0 commit comments

Comments
 (0)