Merge branch 'PHP-7.2' into PHP-7.3

* PHP-7.2:
  Fix #76859 stream_get_line skips data if used with data-generating filter
This commit is contained in:
Joe Watkins 2019-10-03 06:50:58 +02:00
commit 5b1bb23edf
No known key found for this signature in database
GPG Key ID: F9BA0ADA31CBD89E
5 changed files with 38 additions and 6 deletions

2
NEWS
View File

@ -33,6 +33,8 @@ PHP NEWS
(Thomas Calvet)
. Fixed bug #78612 (strtr leaks memory when integer keys are used and the
subject string shorter). (Nikita)
. Fixed bug #76859 (stream_get_line skips data if used with data-generating
filter). (kkopachev)
26 Sep 2019, PHP 7.3.10

View File

@ -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.

View File

@ -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

View File

@ -359,8 +359,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;

View File

@ -524,10 +524,6 @@ PHPAPI void _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);