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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: thomas dot gerbet at enalean dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Mon Dec 30 14:01:28 2024 UTC