xref: /PHP-8.0/ext/fileinfo/tests/bug78987.phpt (revision 8f75ab0d)
1--TEST--
2Bug #78987 High memory usage during encoding detection
3--SKIPIF--
4<?php require_once(__DIR__ . '/skipif.inc'); ?>
5--INI--
6memory_limit=512M
7--FILE--
8<?php
9$finfo = new finfo(FILEINFO_MIME_TYPE);
10$minSize = 128 * 1024;
11$maxSize = 16 * 1024 * 1024;
12
13$map = array(
14	131072 => 9113600,
15	262144 => 9113600,
16	524288 => 10850304,
17	1048576 => 11210752,
18	2097152 => 13312000,
19	4194304 => 17510400,
20	8388608 => 23801856,
21	16777216 => 36384768,
22);
23for($size = $minSize; $size <= $maxSize; $size *= 2) {
24	$content = str_repeat('0', $size);
25
26	$finfo->buffer($content);
27
28	$m = memory_get_peak_usage(true);
29	printf("%-8d => %s\n", $size, $m <= $map[$size] ? "ok" : "$m");
30}
31?>
32--EXPECT--
33131072   => ok
34262144   => ok
35524288   => ok
361048576  => ok
372097152  => ok
384194304  => ok
398388608  => ok
4016777216 => ok
41