php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login

Patch fill_up_to_possible_while_preventing_leak_61058 for *General Issues Bug #61058

Patch version 2012-02-12 05:43 UTC

Return to Bug #61058 | Download this patch
Patch Revisions:

Developer: carloschilazo@gmail.com

Index: ext/standard/array.c
===================================================================
--- ext/standard/array.c	(revision 323161)
+++ ext/standard/array.c	(working copy)
@@ -1543,7 +1543,7 @@
 {
 	zval *val;
 	long start_key, num;
-
+	long long maximum_key,exceeding_keys;
 	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llz", &start_key, &num, &val) == FAILURE) {
 		return;
 	}
@@ -1553,6 +1553,13 @@
 		RETURN_FALSE;
 	}
 
+        /* if key overflows allocate the maximum possible, prevent memory leak. Bug #61058 */
+        maximum_key = (long long)(start_key + num);
+        exceeding_keys = (long long)(maximum_key - LONG_MAX);
+        if(maximum_key < 0){
+                num = LONG_MAX-start_key+1;
+        }
+
 	/* allocate an array for return */
 	array_init_size(return_value, num);
 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 09:01:30 2024 UTC