Pattern: Inexact read with Stream.Read
Issue: -
Stream.Read
and Stream.ReadAsync
might return fewer bytes than requested, resulting in unreliable code if the return value isn't checked.
Example of incorrect code:
void Test(Stream stream, byte[] buffer)
{
stream.Read(buffer, 0, buffer.Length);
}
Example of correct code:
void Test(Stream stream, byte[] buffer)
{
stream.ReadExactly(buffer);
}