From d020e809a1a980ccdfddf64d6074d7d2cfd67442 Mon Sep 17 00:00:00 2001 From: kpreisser Date: Tue, 23 Jan 2018 10:45:58 +0100 Subject: [PATCH] Fix infinite loop that can occur when the client closes the connection before sending the complete packet body. --- .../MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs b/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs index 57b7972..a4300ec 100644 --- a/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs +++ b/Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs @@ -137,6 +137,12 @@ namespace MQTTnet.Adapter do { var readBytesCount = await stream.ReadAsync(body, offset, body.Length - offset, cancellationToken).ConfigureAwait(false); + // Check if the client closed the connection before sending the full body. + if (readBytesCount == 0) + { + throw new MqttCommunicationException("Connection closed while reading remaining packet body."); + } + offset += readBytesCount; } while (offset < header.BodyLength);