summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS4
-rw-r--r--ext/standard/tests/streams/bug46147.phpt14
-rw-r--r--ext/standard/tests/streams/bug76859.phpt22
-rw-r--r--main/streams/filter.c2
-rw-r--r--main/streams/streams.c4
5 files changed, 40 insertions, 6 deletions
diff --git a/NEWS b/NEWS
index 23890c7d7a..06cd74d5a8 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,10 @@ PHP NEWS
. Fixed bug #75245 (Don't set content of elements with only whitespaces).
(eriklundin)
+- Standard:
+ . Fixed bug #76859 (stream_get_line skips data if used with data-generating
+ filter). (kkopachev)
+
03 Oct 2019, PHP 7.4.0RC3
- Core:
diff --git a/ext/standard/tests/streams/bug46147.phpt b/ext/standard/tests/streams/bug46147.phpt
new file mode 100644
index 0000000000..bed2ee5472
--- /dev/null
+++ b/ext/standard/tests/streams/bug46147.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Bug #46147 (after stream seek, appending stream filter reads incorrect data)
+--FILE--
+<?php
+$fp = tmpfile();
+fwrite($fp, "this is a lowercase string.\n");
+fseek($fp, 5);
+stream_filter_append($fp, "string.toupper");
+while (!feof($fp)) {
+ echo fread($fp, 5);
+}
+
+--EXPECT--
+IS A LOWERCASE STRING.
diff --git a/ext/standard/tests/streams/bug76859.phpt b/ext/standard/tests/streams/bug76859.phpt
new file mode 100644
index 0000000000..268b06a01b
--- /dev/null
+++ b/ext/standard/tests/streams/bug76859.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Bug #76859 (stream_get_line skips data if used with filters)
+--FILE--
+<?php
+
+$data = '123';
+
+$fh = fopen('php://memory', 'r+b');
+fwrite($fh, $data);
+rewind($fh);
+stream_filter_append($fh, 'string.rot13', STREAM_FILTER_READ);
+
+$out = '';
+while (!feof($fh)) {
+ $out .= stream_get_line($fh, 1024);
+}
+
+fclose($fh);
+
+echo strlen($out) . "\n";
+--EXPECT--
+3
diff --git a/main/streams/filter.c b/main/streams/filter.c
index 7fdbd0c3bf..f536b92a02 100644
--- a/main/streams/filter.c
+++ b/main/streams/filter.c
@@ -360,8 +360,6 @@ PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_strea
case PSFS_PASS_ON:
/* If any data is consumed, we cannot rely upon the existing read buffer,
as the filtered data must replace the existing data, so invalidate the cache */
- /* note that changes here should be reflected in
- main/streams/streams.c::php_stream_fill_read_buffer */
stream->writepos = 0;
stream->readpos = 0;
diff --git a/main/streams/streams.c b/main/streams/streams.c
index aef1ebe762..1f6fc89a79 100644
--- a/main/streams/streams.c
+++ b/main/streams/streams.c
@@ -534,10 +534,6 @@ PHPAPI int _php_stream_fill_read_buffer(php_stream *stream, size_t size)
php_stream_bucket_brigade brig_in = { NULL, NULL }, brig_out = { NULL, NULL };
php_stream_bucket_brigade *brig_inp = &brig_in, *brig_outp = &brig_out, *brig_swap;
- /* Invalidate the existing cache, otherwise reads can fail, see note in
- main/streams/filter.c::_php_stream_filter_append */
- stream->writepos = stream->readpos = 0;
-
/* allocate a buffer for reading chunks */
chunk_buf = emalloc(stream->chunk_size);