Skip to content

Commit a26f632

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
2 parents d1646e3 + 16d35eb commit a26f632

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

Zend/zend_alloc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ static void *zend_mm_alloc_pages(zend_mm_heap *heap, uint32_t pages_count ZEND_F
982982
heap->cached_chunks = chunk->next;
983983
} else {
984984
#if ZEND_MM_LIMIT
985-
if (UNEXPECTED(heap->real_size + ZEND_MM_CHUNK_SIZE > heap->limit)) {
985+
if (UNEXPECTED(ZEND_MM_CHUNK_SIZE > heap->limit - heap->real_size)) {
986986
if (zend_mm_gc(heap)) {
987987
goto get_chunk;
988988
} else if (heap->overflow == 0) {
@@ -1510,8 +1510,8 @@ static zend_never_inline void *zend_mm_realloc_huge(zend_mm_heap *heap, void *pt
15101510
}
15111511
} else /* if (new_size > old_size) */ {
15121512
#if ZEND_MM_LIMIT
1513-
if (UNEXPECTED(heap->real_size + (new_size - old_size) > heap->limit)) {
1514-
if (zend_mm_gc(heap) && heap->real_size + (new_size - old_size) <= heap->limit) {
1513+
if (UNEXPECTED(new_size - old_size > heap->limit - heap->real_size)) {
1514+
if (zend_mm_gc(heap) && new_size - old_size <= heap->limit - heap->real_size) {
15151515
/* pass */
15161516
} else if (heap->overflow == 0) {
15171517
#if ZEND_DEBUG
@@ -1799,8 +1799,8 @@ static void *zend_mm_alloc_huge(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_D
17991799
void *ptr;
18001800

18011801
#if ZEND_MM_LIMIT
1802-
if (UNEXPECTED(heap->real_size + new_size > heap->limit)) {
1803-
if (zend_mm_gc(heap) && heap->real_size + new_size <= heap->limit) {
1802+
if (UNEXPECTED(new_size > heap->limit - heap->real_size)) {
1803+
if (zend_mm_gc(heap) && new_size <= heap->limit - heap->real_size) {
18041804
/* pass */
18051805
} else if (heap->overflow == 0) {
18061806
#if ZEND_DEBUG
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
No overflow should occur during the memory_limit check for wordwrap()
3+
--SKIPIF--
4+
<?php
5+
if (getenv("USE_ZEND_ALLOC") === "0") die("skip Zend MM disabled");
6+
?>
7+
--INI--
8+
memory_limit=128M
9+
--FILE--
10+
<?php
11+
12+
$str = str_repeat('x', 65534);
13+
$str2 = str_repeat('x', 65535);
14+
wordwrap($str, 1, $str2);
15+
16+
?>
17+
--EXPECTF--
18+
Fatal error: Allowed memory size of 134217728 bytes exhausted%s(tried to allocate %d bytes) in %s on line %d

0 commit comments

Comments
 (0)