xref: /PHP-7.0/ext/zlib/tests/bug74240.phpt (revision 7fba8bda)
1--TEST--
2Bug #74240 (deflate_add can allocate too much memory)
3--SKIPIF--
4<?php
5if (!extension_loaded("zlib")) {
6    print "skip - ZLIB extension not loaded";
7}
8?>
9--FILE--
10<?php
11
12ini_set('memory_limit', '64M');
13
14$deflator = deflate_init(ZLIB_ENCODING_RAW);
15
16$bytes = str_repeat("*", 65536);
17
18// this crashes after about 500 iterations if PHP is
19// configured for 64M
20for ($i = 0; $i < 1000; $i++) {
21    $output = deflate_add(
22        $deflator,
23        $bytes,
24        ZLIB_SYNC_FLUSH
25    );
26}
27echo "Completed\n";
28?>
29--EXPECT--
30Completed
31