php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79235 Large consumption of memory when using a user filter
Submitted: 2020-02-06 12:58 UTC Modified: 2020-02-06 13:16 UTC
From: thomas dot gerbet at enalean dot com Assigned:
Status: Duplicate Package: Streams related
PHP Version: 7.3.14 OS: Linux
Private report: No CVE-ID: None
 [2020-02-06 12:58 UTC] thomas dot gerbet at enalean dot com
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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-02-06 13:16 UTC] nikic@php.net
-Status: Open +Status: Duplicate
 [2020-02-06 13:16 UTC] nikic@php.net
Duplicate of bug #78902, which is already fixed in the upcoming releases.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 08:01:27 2024 UTC