mirror of
https://github.com/php/php-src.git
synced 2024-09-21 09:57:23 +00:00
70dfbe0068
In the case of a stream with no filters, php_stream_fill_read_buffer only reads stream->chunk_size into the read buffer. If the stream has filters attached, it could unnecessarily buffer a large amount of data. With this change, php_stream_fill_read_buffer only proceeds until either the requested size or stream->chunk_size is available in the read buffer. Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de> Closes GH-6444.
29 lines
664 B
PHP
29 lines
664 B
PHP
--TEST--
|
|
Bug #80384 large reads cause filters to internally buffer large amounts of memory
|
|
--FILE--
|
|
<?php
|
|
/* First, create a file to read */
|
|
$tmp_filename = __DIR__ . "/bug80384.tmp";
|
|
$fp = fopen($tmp_filename, 'w');
|
|
for ($i=0; $i<1024; $i++) {
|
|
fwrite($fp, str_repeat('ABCDEFGH', 1024));
|
|
}
|
|
fclose($fp);
|
|
|
|
/* Stream the file through a filter */
|
|
$fp = fopen($tmp_filename, 'r');
|
|
$filter = stream_filter_append($fp, "string.rot13");
|
|
|
|
$mem_start = memory_get_usage();
|
|
fread($fp, 8 * 1024 * 1024);
|
|
$mem_final = memory_get_usage();
|
|
fclose($fp);
|
|
var_dump($mem_final - $mem_start < 32768);
|
|
?>
|
|
--CLEAN--
|
|
<?php
|
|
unlink(__DIR__ . "/bug80384.tmp");
|
|
?>
|
|
--EXPECT--
|
|
bool(true)
|