From 2b475eebbea85779989e98e87753d6b023a1d131 Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Sun, 11 May 2014 17:54:27 -0700 Subject: Fix bug #67247 spl_fixedarray_resize integer overflow --- NEWS | 1 + ext/spl/spl_fixedarray.c | 2 +- ext/spl/tests/bug67247.phpt | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 ext/spl/tests/bug67247.phpt diff --git a/NEWS b/NEWS index 73531dd624..03f8b87daf 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ PHP NEWS . Fixed bug #67072 (Echoing unserialized "SplFileObject" crash). (Anatol) . Fixed bug #67245 (usage of memcpy() with overlapping src and dst in zend_exceptions.c). (Bob) + . Fixed bug #67247 (spl_fixedarray_resize integer overflow). (Stas) - Date: . Fixed bug #67118 (DateTime constructor crash with invalid data). (Anatol) diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index 2f5e8c670b..22f766f67d 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 0000000000..cb71445d7b --- /dev/null +++ b/ext/spl/tests/bug67247.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #67247 (spl_fixedarray_resize integer overflow) +--FILE-- +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 -- cgit v1.2.1