8000 Consider exposing a max response buffer size · Issue #203 · oras-project/oras-dotnet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content 8000
Consider exposing a max response buffer size #203
Open
@akashsinghal

Description

@akashsinghal

What is the version or commit of the ORAS .NET library?

No response

What would you like to be added?

It seems the ORAS dotnet ManifestStore operations utilize the HttpResponse.Content.ReadAsStreamAsync for loading response body content into a stream. This can be potentially unsafe as the underlying MemoryStream buffer size is by default set to be the Int.MaxSize which comes to be ~2gb. This can lead to potential memory exhaustion if the upstream server is malicious and reports an incorrect Content-Length in the headers. There should be a check to enforce a max size (maybe 4mb) and have this be overridable.

return await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);

Taking a look at the source code for ReadAsStreamAsync,
https://github.com/dotnet/runtime/blob/5535e31a712343a63f5d7d796cd874e563e5ac14/src/libraries/System.Net.Http/src/System/Net/Http/HttpContent.cs#L286
you can see that if the content has not been loaded before into a temporary buffer, a new buffer is created with the size MaxSizeBytes
https://github.com/dotnet/runtime/blob/5535e31a712343a63f5d7d796cd874e563e5ac14/src/libraries/System.Net.Http/src/System/Net/Http/HttpContent.cs#L550

Why is this needed for the ORAS .NET library?

Protect clients from large responses.

Are you willing to submit PRs to contribute to this feature?

  • Yes, I am willing to implement it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0