Repro:
using System.Drawing;
byte[] ico;
using (var hc = new HttpClient())
{
ico = await new HttpClient().GetByteArrayAsync(@"https://github.com/dotnet/runtime/main/src/native/corehost/dotnet/dotnet.ico");
}
var stream = new TrickleStream(ico);
new Icon(stream);
class TrickleStream : MemoryStream
{
public TrickleStream(byte[] bytes) : base(bytes) { }
public override int Read(byte[] buffer, int offset, int count) =>
base.Read(buffer, offset, Math.Min(count, 1));
public override int Read(Span<byte> buffer) =>
base.Read(buffer.IsEmpty ? buffer : buffer.Slice(0, 1));
}
This should successfully load the data from the Stream into the icon, but instead it throws an exception.
All of these should be updated to not assume Stream.Read will return as much data as was requested.
|
f.Read(_iconData, 0, _iconData.Length); |
|
stream.Read(_iconData, 0, _iconData.Length); |
|
stream.Read(_iconData, 0, _iconData.Length); |
|
dataStream.Read(image._rawData, 0, (int)dataStream.Length); |
cc: @eerhardt
Repro:
This should successfully load the data from the Stream into the icon, but instead it throws an exception.
All of these should be updated to not assume Stream.Read will return as much data as was requested.
runtime/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.cs
Line 75 in 1928cd2
runtime/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.cs
Line 113 in 1928cd2
runtime/src/libraries/System.Drawing.Common/src/System/Drawing/Icon.cs
Line 130 in 1928cd2
runtime/src/libraries/System.Drawing.Common/src/System/Drawing/Image.cs
Line 1057 in 1928cd2
cc: @eerhardt