1--TEST--
2GH-81475: Memory leak during stream filter failure
3--SKIPIF--
4<?php require 'filter_errors.inc'; filter_errors_skipif('zlib.inflate'); ?>
5--FILE--
6<?php
7// Prepare a big enough input so that it is not entirely buffered
8$stream = fopen('php://memory', 'r+');
9$content = '';
10for ($i = 0; $i < 10000; $i++) {
11	$content .= "Hello $i\n";
12}
13fwrite($stream, gzcompress($content));
14
15// Mess up the checksum
16fseek($stream, -1, SEEK_CUR);
17fwrite($stream, '1');
18
19// Rewind and add the zlib filter
20rewind($stream);
21stream_filter_append($stream, 'zlib.inflate', STREAM_FILTER_READ, ['window' => 15]);
22
23// Read the filtered stream line by line.
24while (($line = fgets($stream)) !== false) {
25	$error = error_get_last();
26	if ($error !== null) {
27		// An error is thrown but fgets didn't return false
28		var_dump(error_get_last());
29		var_dump($line);
30	}
31}
32
33fclose($stream);
34?>
35--EXPECTF--
36
37Notice: fgets(): zlib: data error in %s on line %d
38array(4) {
39  ["type"]=>
40  int(8)
41  ["message"]=>
42  string(25) "fgets(): zlib: data error"
43  ["file"]=>
44  string(%d) "%s"
45  ["line"]=>
46  int(%d)
47}
48string(7) "Hello 6"
49
50