-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SqlBytes from Stream doesn't work for partial reads #80259
Comments
Tagging subscribers to this area: @roji, @ajcvickers Issue DetailsRepro: using System.Data.SqlTypes;
var stream = new TrickleStream(new byte[] { 1, 2, 3, 4, 5 });
var bytes = new SqlBytes(stream);
Console.WriteLine(BitConverter.ToString(bytes.Buffer));
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));
} That should output: 01-02-03-04-05 but ends up outputting: 01-00-00-00-00 The Stream.Read operations SqlBytes performs assumes Read will always read as much as was requested, which isn't guaranteed:
|
Related: |
/cc @David-Engel |
Tagging subscribers to this area: @cheenamalhotra, @David-Engel Issue DetailsRepro: using System.Data.SqlTypes;
var stream = new TrickleStream(new byte[] { 1, 2, 3, 4, 5 });
var bytes = new SqlBytes(stream);
Console.WriteLine(BitConverter.ToString(bytes.Buffer));
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));
} That should output: 01-02-03-04-05 but ends up outputting: 01-00-00-00-00 The Stream.Read operations SqlBytes/SqlChars performs assumes Read will always read as much as was requested, which isn't guaranteed:
|
Repro:
That should output:
but ends up outputting:
The Stream.Read operations SqlBytes performs assumes Read will always read as much as was requested, which isn't guaranteed:
runtime/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLBytes.cs
Line 182 in 5a10aa6
runtime/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLBytes.cs
Line 322 in 5a10aa6
runtime/src/libraries/System.Data.Common/src/System/Data/SQLTypes/SQLBytes.cs
Line 459 in 5a10aa6
cc: @roji, @eerhardt
The text was updated successfully, but these errors were encountered: