Bug #79235 [NEW]: Large consumption of memory when using a user filter
| From: | thomas dot gerbet at enalean dot com | Date: | Thu, 06 Feb 2020 12:58:32 +0000 |
| Subject: | Bug #79235 [NEW]: Large consumption of memory when using a user filter | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-225385@lists.php.net to get a copy of this message | ||
From: thomas dot gerbet at enalean dot com
Operating system: Linux
PHP version: 7.3.14
Package: Streams related
Bug Type: Bug
Bug description:Large consumption of memory when using a user filter
Description:
------------
Since PHP 7.3.11 (it looks like it is the case since
https://github.com/php/php-src/commit/05560b67bc87a2bcbfd5b48a48443a62f3311e7d)
processing a stream with a PHP user filter consumes at least the same
amount of memory that the size of the processed data. It was not the
case before.
Test script:
---------------
<?php
$input_resource = fopen('/dev/zero', 'rb');
$dev_null = fopen('/dev/null', 'wb+');
class TestFilter extends \php_user_filter {
public function filter($in, $out, &$consumed, $closing)
{
while ($bucket = \stream_bucket_make_writeable($in)) {
$consumed += $bucket->datalen;
\stream_bucket_append($out, $bucket);
}
return PSFS_PASS_ON;
}
}
\stream_filter_register('testm', \TestFilter::class);
$input_with_filter = \stream_filter_prepend(
$input_resource,
'testm',
STREAM_FILTER_READ
);
stream_copy_to_stream($input_resource, $dev_null, 1 * 1024 * 1024 *
1024);
fclose($dev_null);
fclose($input_resource);
Expected result:
----------------
// No fatal error
Actual result:
--------------
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted
(tried to allocate 65019904 bytes) in example.php on line 24
--
Edit bug report at https://bugs.php.net/bug.php?id=79235&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79235&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79235&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79235&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79235&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79235&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79235&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79235&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79235&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79235&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79235&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79235&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79235&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79235&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79235&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79235&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79235&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79235&r=mysqlcfg