Skip to content

Commit cea28bd

Browse files
committed
Update tests for MemoryError on 32-bit and BSD platforms
1 parent f03f82d commit cea28bd

14 files changed

Lines changed: 144 additions & 42 deletions

Zend/tests/bug55509.phpt

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,24 @@ elseif (PHP_OS == 'FreeBSD') {
6565
memory_limit=2100M
6666
--FILE--
6767
<?php
68-
$a1 = str_repeat("1", 1024 * 1024 * 1024 * 0.5);
69-
echo "1\n";
70-
$a2 = str_repeat("2", 1024 * 1024 * 1024 * 0.5);
71-
echo "2\n";
72-
$a3 = str_repeat("3", 1024 * 1024 * 1024 * 0.5);
73-
echo "3\n";
74-
$a4 = str_repeat("4", 1024 * 1024 * 1024 * 0.5);
75-
echo "4\n";
76-
$a5 = str_repeat("5", 1024 * 1024 * 1024 * 0.5);
77-
echo "5\n";
68+
try {
69+
$a1 = str_repeat("1", 1024 * 1024 * 1024 * 0.5);
70+
echo "1\n";
71+
$a2 = str_repeat("2", 1024 * 1024 * 1024 * 0.5);
72+
echo "2\n";
73+
$a3 = str_repeat("3", 1024 * 1024 * 1024 * 0.5);
74+
echo "3\n";
75+
$a4 = str_repeat("4", 1024 * 1024 * 1024 * 0.5);
76+
echo "4\n";
77+
$a5 = str_repeat("5", 1024 * 1024 * 1024 * 0.5);
78+
echo "5\n";
79+
} catch (Throwable $t) {
80+
echo $t::class . ': ' . $t->getMessage() . "\n";
81+
}
7882
?>
79-
--EXPECTF--
83+
--EXPECT--
8084
1
8185
2
8286
3
8387
4
84-
85-
Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %sbug55509.php on line %d
88+
MemoryError: The resulting string is too large to fit in the configured memory limit

ext/shmop/tests/shmop_read_memory_error.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
shmop_read() throws a catchable MemoryError when the read size cannot fit in the memory limit
33
--EXTENSIONS--
44
shmop
5+
--SKIPIF--
6+
<?php if (PHP_OS_FAMILY === 'Darwin') die('skip MacOS does not allow shared memory size larger than 65,536 bytes'); ?>
57
--INI--
68
memory_limit=32M
79
opcache.enable_cli=0

ext/sockets/tests/socket_read_recv_memory_error.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ opcache.enable_cli=0
1212
--FILE--
1313
<?php
1414

15-
socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $pair);
15+
$domain = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? AF_INET : AF_UNIX;
16+
17+
socket_create_pair($domain, SOCK_STREAM, 0, $pair);
1618
[$a, $b] = $pair;
1719
socket_write($b, 'ping');
1820

ext/standard/tests/array/array_pad_memory_error.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ opcache.enable_cli=0
66
--FILE--
77
<?php
88

9+
$size = PHP_INT_SIZE > 4 ? 50_000_000 : 32_500_000;
10+
911
try {
10-
array_pad([1, 2], 50000000, 0);
12+
array_pad([1, 2], $size, 0);
1113
} catch (MemoryError $e) {
1214
echo $e::class . ': ' . $e->getMessage() . "\n";
1315
}
1416

1517
try {
16-
array_pad([1, 2], -50000000, 0);
18+
array_pad([1, 2], -$size, 0);
1719
} catch (MemoryError $e) {
1820
echo 'negative: ' . $e::class . ': ' . $e->getMessage() . "\n";
1921
}

ext/standard/tests/array/range_memory_error.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ opcache.enable_cli=0
66
--FILE--
77
<?php
88

9+
$size = PHP_INT_SIZE > 4 ? 50_000_000 : 32_500_000;
10+
911
try {
10-
range(0, 50000000);
12+
range(0, $size);
1113
} catch (MemoryError $e) {
1214
echo 'int: ' . $e::class . ': ' . $e->getMessage() . "\n";
1315
}
1416

1517
try {
16-
range(0.5, 50000000.5);
18+
range(0.5, $size + 0.5);
1719
} catch (MemoryError $e) {
1820
echo 'float: ' . $e::class . ': ' . $e->getMessage() . "\n";
1921
}

ext/standard/tests/streams/stream_socket_recvfrom_memory_error.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ opcache.enable_cli=0
1010
--FILE--
1111
<?php
1212

13-
[$a, $b] = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, 0);
13+
$domain = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? STREAM_PF_INET : STREAM_PF_UNIX;
14+
15+
[$a, $b] = stream_socket_pair($domain, STREAM_SOCK_STREAM, 0);
1416
fwrite($b, 'ping');
1517

1618
try {

ext/standard/tests/strings/chunk_split_variation1_32bit.phpt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ echo "*** Testing chunk_split() : unexpected large 'end' string argument variati
1212
$a=str_repeat("B", 65535);
1313
$b=1;
1414
$c=str_repeat("B", 65535);
15-
var_dump(chunk_split($a,$b,$c));
15+
16+
try {
17+
var_dump(chunk_split($a,$b,$c));
18+
} catch (Throwable $t) {
19+
echo $t::class . ': ' . $t->getMessage() . "\n";
20+
}
1621
?>
1722
--EXPECTF--
1823
*** Testing chunk_split() : unexpected large 'end' string argument variation 1 ***
19-
20-
Fatal error: %rAllowed memory size of %d bytes exhausted%s\(tried to allocate %d bytes\)|Possible integer overflow in memory allocation \(4294901777 \+ %d\)%r in %s on line %d
24+
MemoryError: The resulting string is too large to fit in the configured memory limit

ext/standard/tests/strings/chunk_split_variation2_32bit.phpt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ echo "*** Testing chunk_split() : unexpected large 'end' string argument variati
1111
$a=str_repeat("B", 65537);
1212
$b=1;
1313
$c=str_repeat("B", 65537);
14-
var_dump(chunk_split($a,$b,$c));
14+
15+
try {
16+
var_dump(chunk_split($a,$b,$c));
17+
} catch (Throwable $t) {
18+
echo $t::class . ': ' . $t->getMessage() . "\n";
19+
}
1520
?>
1621
--EXPECTF--
1722
*** Testing chunk_split() : unexpected large 'end' string argument variation 2 ***
18-
19-
Fatal error: Possible integer overflow in memory allocation (65537 * 65537 + %r65556|65560%r) in %s on line %d
23+
MemoryError: The resulting string is too large to fit in the configured memory limit

ext/standard/tests/strings/str_pad_variation5.phpt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ echo "*** Testing str_pad() function: with large value for for 'pad_length' argu
2020
//defining '$input' argument
2121
$input = "Test string";
2222
$pad_length = PHP_INT_MAX - 16; /* zend_string header is 16 bytes */
23-
var_dump( str_pad($input, $pad_length) );
23+
24+
try {
25+
var_dump( str_pad($input, $pad_length) );
26+
} catch (Throwable $t) {
27+
echo $t::class . ': ' . $t->getMessage() . "\n";
28+
}
2429

2530
?>
2631
--EXPECTF--
2732
*** Testing str_pad() function: with large value for for 'pad_length' argument ***
28-
29-
Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d
33+
MemoryError: The resulting string is too large to fit in the configured memory limit

ext/zend_test/tests/gh11078.phpt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ class CrashingFifo {
2626
}
2727
}
2828

29-
stream_register_wrapper('fifo', CrashingFifo::class);
30-
$readStream = fopen('fifo://1', 'r');
31-
zend_test_cast_fread($readStream);
29+
try {
30+
stream_register_wrapper('fifo', CrashingFifo::class);
31+
$readStream = fopen('fifo://1', 'r');
32+
zend_test_cast_fread($readStream);
33+
} catch (Throwable $t) {
34+
echo $t::class . ': ' . $t->getMessage() . "\n";
35+
}
3236

3337
?>
34-
--EXPECTF--
35-
Fatal error: Allowed memory size of %d bytes exhausted %s
38+
--EXPECT--
39+
MemoryError: The resulting string is too large to fit in the configured memory limit

0 commit comments

Comments
 (0)