Aspnetcore: ReferenceReadStream is not compatible with CryptoStream

Created on 22 Jan 2020  路  2Comments  路  Source: dotnet/aspnetcore

Describe the bug

Very similar to https://github.com/aspnet/KestrelHttpServer/issues/2341 (PR https://github.com/aspnet/KestrelHttpServer/pull/2342) the ReferenceReadStream does throw a NotSupportedException in its Flush method when it should not.

To Reproduce

using(var cs = new CryptoStream(formFile.OpenReadStream(), ...))
{
    throw new Exception("stream has not been read completely and therefore CryptoStream will call Flush");
}

This should not trigger a NotSupportedException.

Further technical details

  • ASP.NET Core version 2.1.x on .NET Framework 4.7.2
Done area-servers bug good first issue help wanted

Most helpful comment

Seems reasonable to just no-op in Flush instead of throwing.

The simplest workaround you can use for now (and in 2.1, since the change would be in 5.0) would be to build your own wrapper that forwards all calls to the inner stream except Flush and then wrap that around ReferenceReadStream.

All 2 comments

Seems reasonable to just no-op in Flush instead of throwing.

The simplest workaround you can use for now (and in 2.1, since the change would be in 5.0) would be to build your own wrapper that forwards all calls to the inner stream except Flush and then wrap that around ReferenceReadStream.

A pity it's not backported, but I guess the workaround is good enough. Thank you for the quick response.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

githubgitgit picture githubgitgit  路  3Comments

FourLeafClover picture FourLeafClover  路  3Comments

rbanks54 picture rbanks54  路  3Comments

TanvirArjel picture TanvirArjel  路  3Comments

BrennanConroy picture BrennanConroy  路  3Comments