xref: /PHP-7.4/Zend/tests/bug55509.phpt (revision 704a0ab0)
1--TEST--
2Bug #55509 (segfault on x86_64 using more than 2G memory)
3--SKIPIF--
4<?php
5if (PHP_INT_SIZE == 4) {
6  die('skip Not for 32-bits OS');
7}
8
9$zend_mm_enabled = getenv("USE_ZEND_ALLOC");
10if ($zend_mm_enabled === "0") {
11    die("skip Zend MM disabled");
12}
13
14if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
15// check the available memory
16if (PHP_OS == 'Linux') {
17  $lines = file('/proc/meminfo');
18  $infos = array();
19  foreach ($lines as $line) {
20    $tmp = explode(":", $line);
21    $index = strtolower($tmp[0]);
22    $value = (int)ltrim($tmp[1], " ")*1024;
23    $infos[$index] = $value;
24  }
25  $freeMemory = $infos['memfree']+$infos['buffers']+$infos['cached'];
26  if ($freeMemory < 2100*1024*1024) {
27    die('skip Not enough memory.');
28  }
29}
30elseif (PHP_OS == 'FreeBSD') {
31  $lines = explode("\n",`sysctl -a`);
32  $infos = array();
33  foreach ($lines as $line) {
34    if(!$line){
35      continue;
36    }
37    $tmp = explode(":", $line);
38    $index = strtolower($tmp[0]);
39    $value = trim($tmp[1], " ");
40    $infos[$index] = $value;
41  }
42  $freeMemory = ($infos['vm.stats.vm.v_inactive_count']*$infos['hw.pagesize'])
43                +($infos['vm.stats.vm.v_cache_count']*$infos['hw.pagesize'])
44                +($infos['vm.stats.vm.v_free_count']*$infos['hw.pagesize']);
45  if ($freeMemory < 2100*1024*1024) {
46    die('skip Not enough memory.');
47  }
48} elseif (PHP_OS == "WINNT") {
49  $s = trim(shell_exec("wmic OS get FreeVirtualMemory /Value 2>nul"));
50  $freeMemory = explode('=', $s)[1]*1;
51
52  if ($freeMemory < 2.1*1024*1024) {
53    die('skip Not enough memory.');
54  }
55}
56?>
57--INI--
58memory_limit=2100M
59--FILE--
60<?php
61$a1 = str_repeat("1", 1024 * 1024 * 1024 * 0.5);
62echo "1\n";
63$a2 = str_repeat("2", 1024 * 1024 * 1024 * 0.5);
64echo "2\n";
65$a3 = str_repeat("3", 1024 * 1024 * 1024 * 0.5);
66echo "3\n";
67$a4 = str_repeat("4", 1024 * 1024 * 1024 * 0.5);
68echo "4\n";
69$a5 = str_repeat("5", 1024 * 1024 * 1024 * 0.5);
70echo "5\n";
71?>
72--EXPECTF--
731
742
753
764
77
78Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %sbug55509.php on line %d
79