Git Product home page Git Product logo

Comments (10)

benmwatson avatar benmwatson commented on May 26, 2024 1

What about adding API to zero out the stream, so the caller is responsible. That would avoid having to add an if check that most people don't need.

from microsoft.io.recyclablememorystream.

lklein53 avatar lklein53 commented on May 26, 2024 1

I want to add zeroing to prevent accidental data leaks.

from microsoft.io.recyclablememorystream.

benmwatson avatar benmwatson commented on May 26, 2024

I'm not opposed to this. Go for it.

from microsoft.io.recyclablememorystream.

grbell-ms avatar grbell-ms commented on May 26, 2024

Do you want to add zeroing to prevent accidental data leaks or so that new streams only contain zeros? In the latter case, note that new blocks are allocated using GC.AllocateUninitializedArray which can return arrays with non-zero content.

from microsoft.io.recyclablememorystream.

lklein53 avatar lklein53 commented on May 26, 2024

What about adding API to zero out the stream, so the caller is responsible. That would avoid having to add an if check that most people don't need.

With the API approach one would have the risk of accidental data leak in case the caller forgets to explicitly zero out memory. Also the combination with `AggressiveBufferReturn`` seems tricky.
I see the point of not adding an if check that most people don't need.
Not sure how to proceed as i think the API approach is already possible by wrapping the stream and calling

CryptographicOperations.ZeroMemory(wrappedStream.GetBuffer());

from microsoft.io.recyclablememorystream.

grbell-ms avatar grbell-ms commented on May 26, 2024

Calling GetBuffer() won't return the encapsulated buffers if there are more than one. Do something like this instead:

var buffers = someStream.GetReadOnlySequence();
foreach (var buffer in buffers)
{
    CryptographicOperations.ZeroMemory(buffer.Span);
}

from microsoft.io.recyclablememorystream.

lklein53 avatar lklein53 commented on May 26, 2024

This won't work as the buffers are read-only. buffer.Span will return a ReadOnlySpan

from microsoft.io.recyclablememorystream.

grbell-ms avatar grbell-ms commented on May 26, 2024

D'oh, you're right. It'd have to be something like this:

var buffers = someStream.GetReadOnlySequence();
foreach (var buffer in buffers)
{
    ref var bytes = ref MemoryMarshal.GetReference(buffer.Span);
    var span = MemoryMarshal.CreateSpan(ref bytes, buffer.Length);
    CryptographicOperations.ZeroMemory(span);
}

But that still won't handle the large buffer if GetBuffer() was ever called during the lifetime of the stream.

from microsoft.io.recyclablememorystream.

lklein53 avatar lklein53 commented on May 26, 2024

Would it be okay then to zero out the buffers (only if configured) before returning them to the pool ?
This would require an additional if check

from microsoft.io.recyclablememorystream.

benmwatson avatar benmwatson commented on May 26, 2024

Would it be okay then to zero out the buffers (only if configured) before returning them to the pool ? This would require an additional if check

I think this fine. Let's make this a 3.0 feature.

from microsoft.io.recyclablememorystream.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.