Skip to content

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

Closed

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.

Activity

  1. added 2 commits that reference this issue on Jul 7, 2023
    4a08c96
  2. added a commit that references this issue on Jan 31, 2024
    4a5d13e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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