improve exceptions in case of corrupt packages close pipes after exception occoured to avoid lingering connections should fix #788

This commit is contained in:
JanEggers
2020-07-09 21:19:00 +02:00
parent 6a564a0c72
commit 33e4ec1943
10 changed files with 134 additions and 21 deletions
@@ -117,6 +117,10 @@ namespace MQTTnet.AspNetCore
var span = _buffer.Span;
var length = BinaryPrimitives.ReadUInt16BigEndian(span.Slice(_offset));
if (Length < _offset + length)
{
throw new MqttProtocolViolationException($"Expected at least {_offset + 2 + length} bytes but there are only {Length} bytes");
}
var result = span.Slice(_offset + 2, length);
_offset += 2 + length;
return result;