Skip to content

Commit 19dd705

Browse files
committed
Fixed bug #55509 (segfault on x86_64 using more than 2G memory). (Laruence)
1 parent c8be503 commit 19dd705

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

Zend/tests/bug55509.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Bug #55509 (segfault on x86_64 using more than 2G memory)
3+
--SKIPIF--
4+
<?php
5+
if (PHP_INT_SIZE == 4) {
6+
die('skip Not for 32-bits OS');
7+
}
8+
?>
9+
--INI--
10+
memory_limit=3G
11+
--FILE--
12+
<?php
13+
$a1 = str_repeat("1", 1024 * 1024 * 1024 * 0.5);
14+
echo "1\n";
15+
$a2 = str_repeat("2", 1024 * 1024 * 1024 * 0.5);
16+
echo "2\n";
17+
$a3 = str_repeat("3", 1024 * 1024 * 1024 * 0.5);
18+
echo "3\n";
19+
$a4 = str_repeat("4", 1024 * 1024 * 1024 * 0.5);
20+
echo "4\n";
21+
$a5 = str_repeat("5", 1024 * 1024 * 1024 * 0.5);
22+
echo "5\n";
23+
$a6 = str_repeat("6", 1024 * 1024 * 1024 * 0.5);
24+
echo "6\n";
25+
?>
26+
--EXPECTF--
27+
1
28+
2
29+
3
30+
4
31+
5
32+
33+
Fatal error: Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) in %s/bug55509.php on line %d

Zend/zend_alloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ static unsigned int _zend_mm_cookie = 0;
515515
#define ZEND_MM_IS_GUARD_BLOCK(b) (((b)->info._size & ZEND_MM_TYPE_MASK) == ZEND_MM_GUARD_BLOCK)
516516

517517
#define ZEND_MM_NEXT_BLOCK(b) ZEND_MM_BLOCK_AT(b, ZEND_MM_BLOCK_SIZE(b))
518-
#define ZEND_MM_PREV_BLOCK(b) ZEND_MM_BLOCK_AT(b, -(int)((b)->info._prev & ~ZEND_MM_TYPE_MASK))
518+
#define ZEND_MM_PREV_BLOCK(b) ZEND_MM_BLOCK_AT(b, -(ssize_t)((b)->info._prev & ~ZEND_MM_TYPE_MASK))
519519

520520
#define ZEND_MM_PREV_BLOCK_IS_FREE(b) (!((b)->info._prev & ZEND_MM_USED_BLOCK))
521521

0 commit comments

Comments
 (0)