Skip to content

CryptoStream.Dispose calls Flush on read-only Stream in CryptoStreamMode.Read #25129

@kekekeks

Description

@kekekeks
class ReadOnlyStream : Stream
{
    public override void Flush() => throw new NotSupportedException();

    public override int Read(byte[] buffer, int offset, int count) => count;

    public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();

    public override void SetLength(long value) => throw new NotSupportedException();

    public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException();

    public override bool CanRead => true;

    public override bool CanSeek => false;

    public override bool CanWrite => false;

    public override long Length => throw new NotSupportedException();

    public override long Position
    {
        get => throw new NotSupportedException();
        set => throw new NotSupportedException();
    }
}
        

static void Main(string[] args)
{
    var aes = Aes.Create().CreateDecryptor();
    var crypto = new CryptoStream(new ReadOnlyStream(), aes, CryptoStreamMode.Read, false);
    crypto.Dispose();
}

I'm not sure if that's the intended behavior, but it makes no logical sense to me and also prevents me from reading encrypted payload from http requests in ASP.NET Core.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions