Skip to content

Commit de83036

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #76859 stream_get_line skips data if used with data-generating filter
2 parents a46bdcb + 5b1bb23 commit de83036

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ PHP NEWS
1010
. Fixed bug #75245 (Don't set content of elements with only whitespaces).
1111
(eriklundin)
1212

13+
- Standard:
14+
. Fixed bug #76859 (stream_get_line skips data if used with data-generating
15+
filter). (kkopachev)
16+
1317
03 Oct 2019, PHP 7.4.0RC3
1418

1519
- Core:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Bug #46147 (after stream seek, appending stream filter reads incorrect data)
3+
--FILE--
4+
<?php
5+
$fp = tmpfile();
6+
fwrite($fp, "this is a lowercase string.\n");
7+
fseek($fp, 5);
8+
stream_filter_append($fp, "string.toupper");
9+
while (!feof($fp)) {
10+
echo fread($fp, 5);
11+
}
12+
13+
--EXPECT--
14+
IS A LOWERCASE STRING.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #76859 (stream_get_line skips data if used with filters)
3+
--FILE--
4+
<?php
5+
6+
$data = '123';
7+
8+
$fh = fopen('php://memory', 'r+b');
9+
fwrite($fh, $data);
10+
rewind($fh);
11+
stream_filter_append($fh, 'string.rot13', STREAM_FILTER_READ);
12+
13+
$out = '';
14+
while (!feof($fh)) {
15+
$out .= stream_get_line($fh, 1024);
16+
}
17+
18+
fclose($fh);
19+
20+
echo strlen($out) . "\n";
21+
--EXPECT--
22+
3

main/streams/filter.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,6 @@ PHPAPI int php_stream_filter_append_ex(php_stream_filter_chain *chain, php_strea
360360
case PSFS_PASS_ON:
361361
/* If any data is consumed, we cannot rely upon the existing read buffer,
362362
as the filtered data must replace the existing data, so invalidate the cache */
363-
/* note that changes here should be reflected in
364-
main/streams/streams.c::php_stream_fill_read_buffer */
365363
stream->writepos = 0;
366364
stream->readpos = 0;
367365

main/streams/streams.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,6 @@ PHPAPI int _php_stream_fill_read_buffer(php_stream *stream, size_t size)
534534
php_stream_bucket_brigade brig_in = { NULL, NULL }, brig_out = { NULL, NULL };
535535
php_stream_bucket_brigade *brig_inp = &brig_in, *brig_outp = &brig_out, *brig_swap;
536536

537-
/* Invalidate the existing cache, otherwise reads can fail, see note in
538-
main/streams/filter.c::_php_stream_filter_append */
539-
stream->writepos = stream->readpos = 0;
540-
541537
/* allocate a buffer for reading chunks */
542538
chunk_buf = emalloc(stream->chunk_size);
543539

0 commit comments

Comments
 (0)