Bug #76859 [NEW]: stream_get_line skips data if used with data-generating filter
| From: | tenzzor at gmail dot com | Date: | Tue, 11 Sep 2018 04:48:21 +0000 |
| Subject: | Bug #76859 [NEW]: stream_get_line skips data if used with data-generating filter | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-216973@lists.php.net to get a copy of this message | ||
From: tenzzor at gmail dot com
Operating system: Linux
PHP version: master-Git-2018-09-11 (Git)
Package: Streams related
Bug Type: Bug
Bug description:stream_get_line skips data if used with data-generating filter
Description:
------------
This is happening with stream filters which create more data then they
consume. For example, base64_encode, zlib.inflate.
The issue is happening because stream_get_line internally calls
php_stream_get_record function, which repeatedly calls
php_stream_fill_read_buffer until enough data is "accumulated" in the
buffer. Problem with that is repeated calls to populate read buffer
force reset state of stream->readpos and stream->writepos in case
filters exist on the stream.
In other words, if on second call to get_record function, buffer holds
some data, but does not have delimiter in it and length of data is less
then required, then function attempts to put more data into buffer,
which is in effect, resets buffer and content is lost.
Test script:
---------------
<?php
$h = fopen('php://temp', 'r+b');
$len = floor(1.5 * 8 * 1024); // 8*1024 == stream->chunk_size. We need a
bit more.
$data = str_repeat('1', $len);
fwrite($h, $data);
rewind($h);
stream_filter_append($h, 'convert.base64-encode');
$out = '';
while (!feof($h)) {
$out .= stream_get_line($h, 1024);
}
fclose($h);
echo $len, ' and ', strlen(base64_decode($out)), PHP_EOL;
assert($data == base64_decode($out));
Expected result:
----------------
12288 and 12288
Actual result:
--------------
12288 and 11520
Warning: assert(): assert($data == base64_decode($out)) failed in
/usr/src/app/t3.php on line 17
--
Edit bug report at https://bugs.php.net/bug.php?id=76859&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76859&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76859&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76859&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76859&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76859&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76859&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76859&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76859&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76859&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76859&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76859&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76859&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76859&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76859&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76859&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76859&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76859&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76859&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76859&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76859&r=mysqlcfg