Browse Source

Always pre-copy the source stream into an in-memory stream so that the subsequent image loading operations can safely use synchronous IO

pull/2006/head
Dan Kroymann 5 years ago
parent
commit
4802b4f0f4
  1. 14
      src/ImageSharp/Image.FromStream.cs

14
src/ImageSharp/Image.FromStream.cs

@ -770,20 +770,6 @@ namespace SixLabors.ImageSharp
throw new NotSupportedException("Cannot read from the stream."); throw new NotSupportedException("Cannot read from the stream.");
} }
// To make sure we don't trigger anything with aspnetcore then we just need to make sure we are
// seekable and we make the copy using CopyToAsync if the stream is seekable then we aren't using
// one of the aspnetcore wrapped streams that error on sync api calls and we can use it without
// having to further wrap
if (stream.CanSeek)
{
if (configuration.ReadOrigin == ReadOrigin.Begin)
{
stream.Position = 0;
}
return await action(stream, cancellationToken).ConfigureAwait(false);
}
using var memoryStream = new ChunkedMemoryStream(configuration.MemoryAllocator); using var memoryStream = new ChunkedMemoryStream(configuration.MemoryAllocator);
await stream.CopyToAsync(memoryStream, configuration.StreamProcessingBufferSize, cancellationToken).ConfigureAwait(false); await stream.CopyToAsync(memoryStream, configuration.StreamProcessingBufferSize, cancellationToken).ConfigureAwait(false);
memoryStream.Position = 0; memoryStream.Position = 0;

Loading…
Cancel
Save