Today I saw a question with code like this:
var accumulator = "";
var buffer = new byte[8192];
while (true)
{
var readed = stream.Read(buffer, 0, buffer.Length);
accumulator += Encoding.UTF8.GetString(buffer, 0, readed);
if (readed < buffer.Length)
break;
}
var result = Encoding.UTF8.GetBytes(accumulator);
I know that this code is inefficient but does it safe? Is there some byte sequence that break the result?