]> granicus.if.org Git - php/commitdiff
MFH: Fixed bug #61058 (array_fill leaks if start index is PHP_INT_MAX)
authorXinchen Hui <laruence@php.net>
Fri, 2 Mar 2012 03:40:40 +0000 (03:40 +0000)
committerXinchen Hui <laruence@php.net>
Fri, 2 Mar 2012 03:40:40 +0000 (03:40 +0000)
NEWS
ext/standard/array.c
ext/standard/tests/array/bug61058.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index c845cef50574da2c3ba5e35cfcd6c7adc794fa64..5048bc880c2417b774a8556553c352ac6adef92e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,10 @@ PHP                                                                        NEWS
   . Fixed bug #60968 (Late static binding doesn't work with 
     ReflectionMethod::invokeArgs()). (Laruence)
 
+- Array:
+  . Fixed bug #61058 (array_fill leaks if start index is PHP_INT_MAX).
+    (Laruence)
+
 01 Mar 2012, PHP 5.4.0 
 
 - Installation:
index 764697c8b778ea1af9b1f70875e6a42798fca1e6..7af2f44b605c08f0fb9c441401e58bfb6dc1ded6 100644 (file)
@@ -1563,12 +1563,17 @@ PHP_FUNCTION(array_fill)
        array_init_size(return_value, num);
 
        num--;
-       zval_add_ref(&val);
        zend_hash_index_update(Z_ARRVAL_P(return_value), start_key, &val, sizeof(zval *), NULL);
+       zval_add_ref(&val);
 
        while (num--) {
-               zval_add_ref(&val);
-               zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &val, sizeof(zval *), NULL);
+               if (zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &val, sizeof(zval *), NULL) == SUCCESS) {
+                       zval_add_ref(&val);
+               } else {
+                       zval_dtor(return_value);
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot add element to the array as the next element is already occupied");
+                       RETURN_FALSE;
+               }
        }
 }
 /* }}} */
diff --git a/ext/standard/tests/array/bug61058.phpt b/ext/standard/tests/array/bug61058.phpt
new file mode 100644 (file)
index 0000000..1f0f6fe
--- /dev/null
@@ -0,0 +1,8 @@
+--TEST--
+Bug #61058 (array_fill leaks if start index is PHP_INT_MAX)
+--FILE--
+<?php 
+array_fill(PHP_INT_MAX, 2, '*');
+?>
+--EXPECTF--
+Warning: array_fill(): Cannot add element to the array as the next element is already occupied in %sbug61058.php on line %d