edgar-mtz-e / slimdx

Automatically exported from code.google.com/p/slimdx
0 stars 0 forks source link

Utilities::ReadStream - exception is thrown when reading from a MemoryStream #419

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In the function:

array<Byte>^ Utilities::ReadStream( Stream^ stream, int readLength, 
DataStream^* dataStream )

There is some code which accesses the internal buffer of a memory stream:

        //if we're reading an entire memory stream from beginning 
to end, just return the internal buffer
        MemoryStream^ ms = dynamic_cast<MemoryStream^>( stream );
        if( ms != nullptr && stream->Position == 0 && readLength 
== stream->Length )
        {
            return ms->GetBuffer();
        }

If the MemoryStream is created in such a way that it's internal buffer is 
not 'exposable' (e.g. by using it's byte[] constructor), the call above to 
MemoryStream::GetBuffer() will throw an UnauthorizedAccessException.

I couldn't find a way to determine if a MemoryStream will allow access to 
it's buffer (aside from catching the exception), so I've just locally 
removed the above block from the function.

Original issue reported on code.google.com by corng...@gmail.com on 27 Jan 2009 at 4:44

GoogleCodeExporter commented 9 years ago
God damnit.

Original comment by promit....@gmail.com on 28 Jan 2009 at 12:32

GoogleCodeExporter commented 9 years ago
Patched for right now by disabling the MemoryStream optimization.

Original comment by promit....@gmail.com on 28 Jan 2009 at 12:56