Bug #77069 [NEW]: stream filter loses final block of data
From: fisharebest at gmail dot com
Operating system: Linux and OSX
PHP version: 7.2.11
Package: Streams related
Bug Type: Bug
Bug description:stream filter loses final block of data
Description:
------------
I'm using a stream filter to process data.
The test case below (also available at https://3v4l.org/kaeRJ)
shows a
stream filter that reverses the text on each line.
Since PHP 7.2, the final block of data is not included in the output.
My initial debugging suggests an issue with the $closing parameter. It
should be set to true when processing the final block of data. Since
PHP 7.2, it is always false.
It worked for PHP 5.5.21 -> 7.1.
It fails for PHP 7.2 and 7.3.
It fails for PHP <= 5.5.20
Test script:
---------------
<?php
class MyFilter extends php_user_filter {
private $data = '';
public function filter($in, $out, &$consumed, $closing) {
$return = PSFS_FEED_ME;
// While input data is available, continue to read it.
while ($bucket_in = stream_bucket_make_writeable($in)) {
$this->data .= $bucket_in->data;
$consumed += $bucket_in->datalen;
// Process whole lines.
while (preg_match('/(.*?)[\r\n]+(.*)/s', $this->data,
$match) === 1) {
list(, $data, $this->data) = $match;
// Send this record output.
$data = strrev($data) . PHP_EOL;
$bucket_out = stream_bucket_new($this->stream, $data);
$return = PSFS_PASS_ON;
stream_bucket_append($out, $bucket_out);
}
}
// Process the final line.
if ($closing && $this->data !== '') {
$data = strrev($this->data) . PHP_EOL;
$bucket_out = stream_bucket_new($this->stream, $data);
$return = PSFS_PASS_ON;
stream_bucket_append($out, $bucket_out);
}
return $return;
}
}
stream_filter_register('my-filter', 'MyFilter');
$input = "Line one\nLine two\nLine three";
$stream = fopen('data://text/plain,' . $input, 'r');
stream_filter_append($stream, 'my-filter');
$output = '';
while (!feof($stream)) {
$output .= fread($stream, 16);
}
fclose($stream);
echo $output;
Expected result:
----------------
eno eniL
owt eniL
eerht eniL
Actual result:
--------------
eno eniL
owt eniL
--
Edit bug report at https://bugs.php.net/bug.php?id=77069&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77069&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77069&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77069&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77069&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77069&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77069&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77069&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77069&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77069&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77069&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77069&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77069&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77069&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77069&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77069&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77069&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77069&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77069&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77069&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77069&r=mysqlcfg
Thread (5 messages)
- fisharebest at gmail dot com