xref: /PHP-8.3/ext/zlib/tests/bug75273.phpt (revision 74859783)
1--TEST--
2Bug #75273 (php_zlib_inflate_filter() may not update bytes_consumed)
3--EXTENSIONS--
4zlib
5--FILE--
6<?php
7function non_repeating_str($len = 8192) {
8    $ret = '';
9    mt_srand(1);
10    $iterations = (int) ($len / 256) + 1;
11    for ($i = 0; $i < $iterations; $i++) {
12        $haves = array();
13        $cnt = 0;
14        while ($cnt < 256) {
15            $j = mt_rand(0, 255);
16            if (!isset($haves[$j])) {
17                $haves[$j] = $j;
18                $cnt++;
19                $ret .= chr($j);
20            }
21        }
22    }
23    return substr($ret, 0, $len);
24}
25
26$base_len = 32768 - 23 /*overhead*/;
27
28$stream = fopen('php://memory', 'rb+');
29
30for ($i = 1; $i <= 8; $i++) {
31    $in_data = non_repeating_str($base_len + $i);
32
33    $deflate_filter = stream_filter_append($stream, 'zlib.deflate',  STREAM_FILTER_WRITE, ['window' => 16 + 15]);
34    rewind($stream);
35    fwrite($stream, $in_data);
36    stream_filter_remove($deflate_filter);
37
38    rewind($stream);
39    $out_data = stream_get_contents($stream);
40    $out_data_len = strlen($out_data);
41
42    $inflate_filter = stream_filter_prepend($stream, 'zlib.inflate',  STREAM_FILTER_WRITE, ['window' => 16 + 15]);
43    rewind($stream);
44    $fwrite_len = fwrite($stream, $out_data);
45    stream_filter_remove($inflate_filter);
46
47    if ($out_data_len !== $fwrite_len) {
48        echo "bug i=$i out_data_len=$out_data_len fwrite_len=$fwrite_len\n";
49    }
50}
51
52fclose($stream);
53?>
54===DONE===
55--EXPECT--
56===DONE===
57