xref: /PHP-8.2/Zend/tests/bug55509.phpt (revision 0123c995)
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    if (count($tmp) < 2) {
39      continue;
40    }
41    $index = strtolower($tmp[0]);
42    $value = trim($tmp[1], " ");
43    $infos[$index] = $value;
44  }
45  $freeMemory = ($infos['vm.stats.vm.v_inactive_count']*$infos['hw.pagesize'])
46                +($infos['vm.stats.vm.v_cache_count']*$infos['hw.pagesize'])
47                +($infos['vm.stats.vm.v_free_count']*$infos['hw.pagesize']);
48  if ($freeMemory < 2100*1024*1024) {
49    die('skip Not enough memory.');
50  }
51} elseif (PHP_OS == "WINNT") {
52  $s = trim(shell_exec("wmic OS get FreeVirtualMemory /Value 2>nul"));
53  $freeMemory = explode('=', $s)[1]*1;
54
55  if ($freeMemory < 2.1*1024*1024) {
56    die('skip Not enough memory.');
57  }
58}
59?>
60--INI--
61memory_limit=2100M
62--FILE--
63<?php
64$a1 = str_repeat("1", 1024 * 1024 * 1024 * 0.5);
65echo "1\n";
66$a2 = str_repeat("2", 1024 * 1024 * 1024 * 0.5);
67echo "2\n";
68$a3 = str_repeat("3", 1024 * 1024 * 1024 * 0.5);
69echo "3\n";
70$a4 = str_repeat("4", 1024 * 1024 * 1024 * 0.5);
71echo "4\n";
72$a5 = str_repeat("5", 1024 * 1024 * 1024 * 0.5);
73echo "5\n";
74?>
75--EXPECTF--
761
772
783
794
80
81Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %sbug55509.php on line %d
82