Skip to content

_php_stream_copy_to_mem: Allow specifying a maximum length without allocating a buffer of that size #11242

Closed
@naderman

Description

@naderman

Description

Currently, if you specify a maxlen for _php_stream_copy_to_mem other than PHP_STREAM_COPY_ALL, the function will allocate a buffer of that size, see https://github.com/php/php-src/blob/master/main/streams/streams.c#L1480

As a consequence there is no way to limit the length of what you want to copy without allocating a buffer that size. So for example, if you want to limit size of a file you're downloading to 1GB, but typical responses you expect are only a few KB, you still allocate the entire GB of memory each time.

Instead I think there should be a way to pass a maxlen and still get the dynamically growing buffer behavior using chunks of PHP_STREAM_COPY_ALL. Userland functions impacted are for example stream_get_contents or file_get_contents.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions