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