diff options
author | Adam Seitz <adamjseitz@gmail.com> | 2020-12-02 00:40:16 +0100 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2020-12-23 13:49:56 +0100 |
commit | 70dfbe00684eb1c31d5b49f643e4736696c3b7df (patch) | |
tree | 3e43f4d84fff8ea5c71fbf429ca4ce625119d138 /tests | |
parent | b043759cb42b33e02359ca1c30d8d5b68d8a015e (diff) | |
download | php-git-70dfbe00684eb1c31d5b49f643e4736696c3b7df.tar.gz |
Fix #80384: limit read buffer size
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.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/basic/bug80384.phpt | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/basic/bug80384.phpt b/tests/basic/bug80384.phpt new file mode 100644 index 0000000000..cf30e8601b --- /dev/null +++ b/tests/basic/bug80384.phpt @@ -0,0 +1,28 @@ +--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) |