From 88de5047bc13f7999e76e460dc0035ac9eb53a5c Mon Sep 17 00:00:00 2001 From: kpreisser Date: Wed, 24 Jan 2018 15:32:36 +0100 Subject: [PATCH] Fix the algorithm for decoding the remaining length to allow a length greater than 2,097,151 bytes. See: https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os.html#_Toc442180732 --- Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs index 5359d99..bcab98d 100644 --- a/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs +++ b/Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs @@ -86,7 +86,7 @@ namespace MQTTnet.Serializer private static async Task ReadBodyLengthFromSourceAsync(Stream stream, CancellationToken cancellationToken) { - // Alorithm taken from http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html. + // Alorithm taken from https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/errata01/os/mqtt-v3.1.1-errata01-os-complete.html. var multiplier = 1; var value = 0; byte encodedByte; @@ -110,11 +110,11 @@ namespace MQTTnet.Serializer readBytes.Add(encodedByte); value += (byte)(encodedByte & 127) * multiplier; - multiplier *= 128; if (multiplier > 128 * 128 * 128) { throw new MqttProtocolViolationException($"Remaining length is invalid (Data={string.Join(",", readBytes)})."); } + multiplier *= 128; } while ((encodedByte & 128) != 0); return value;