Преглед на файлове

Merge pull request #166 from kpreisser/fixDecodeRemainingLength

Fix the algorithm for decoding the body length
release/3.x.x
Christian преди 6 години
committed by GitHub
родител
ревизия
391ee34a0f
No known key found for this signature in database GPG ключ ID: 4AEE18F83AFDEB23
променени са 1 файла, в които са добавени 2 реда и са изтрити 2 реда
  1. +2
    -2
      Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs

+ 2
- 2
Frameworks/MQTTnet.NetStandard/Serializer/MqttPacketReader.cs Целия файл

@@ -86,7 +86,7 @@ namespace MQTTnet.Serializer

private static async Task<int> 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;


Зареждане…
Отказ
Запис