com php-src: Fix bug #67247 spl_fixedarray_re size integer overflow: ext/spl/spl_fixedarray.c e xt/spl/tests/bug67247.phpt
| From: | Johannes Schlüter | Date: | Fri, 18 Jul 2014 22:59:59 +0000 |
| Subject: | com php-src: Fix bug #67247 spl_fixedarray_re size integer overflow: ext/spl/spl_fixedarray.c e xt/spl/tests/bug67247.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-79636@lists.php.net to get a copy of this message | ||
Commit: 84605098bc81517919ecb43935682fdd8a249f9d
Author: Stanislav Malyshev <stas@php.net> Sun, 11 May 2014 17:54:27 -0700
Parents: ee1ab627639b2b6f8da00c687eb2386f93ec2ef6
Branches: PHP-5.3
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=84605098bc81517919ecb43935682fdd8a249f9d
Log:
Fix bug #67247 spl_fixedarray_resize integer overflow
Bugs:
https://bugs.php.net/67247
Changed paths:
M ext/spl/spl_fixedarray.c
A ext/spl/tests/bug67247.phpt
Diff:
diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c
index 646c002..526ed85 100644
--- a/ext/spl/spl_fixedarray.c
+++ b/ext/spl/spl_fixedarray.c
@@ -116,7 +116,7 @@ static void spl_fixedarray_resize(spl_fixedarray *array, long size TSRMLS_DC) /*
array->elements = NULL;
}
} else if (size > array->size) {
- array->elements = erealloc(array->elements, sizeof(zval *) * size);
+ array->elements = safe_erealloc(array->elements, size, sizeof(zval *), 0);
memset(array->elements + array->size, '\0', sizeof(zval *) * (size -
array->size));
} else { /* size < array->size */
long i;
diff --git a/ext/spl/tests/bug67247.phpt b/ext/spl/tests/bug67247.phpt
new file mode 100644
index 0000000..cb71445
--- /dev/null
+++ b/ext/spl/tests/bug67247.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Bug #67247 (spl_fixedarray_resize integer overflow)
+--FILE--
+<?php
+$ar = new SplFixedArray(1);
+echo "size: ".$ar->getSize()."\n";
+$ar->setSize((PHP_INT_SIZE==8)?0x2000000000000001:0x40000001);
+echo "size: "..$ar->getSize()."\n";
+?>
+--EXPECTF--
+size: 1
+
+Fatal error: Possible integer overflow in memory allocation (%d * %d + 0) in %s on line %d