Skip to content

Commit 9b4b529

Browse files
committed
Add safety break when decoding message length
1 parent 8dbfc50 commit 9b4b529

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/MessageProcessors/Mqtt31MessageProcessor.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ public function tryFindMessageInBuffer(string $buffer, int $bufferLength, string
6464
return false;
6565
}
6666

67+
// There can me a maximum of four bytes for the package length, which means we cann opt-out
68+
// when reaching the 6th byte in the buffer. This is only a safety measure in case the broker
69+
// is sending invalid messages. Normally, the loop exits on its own.
70+
if ($byteIndex >= 6) {
71+
break;
72+
}
73+
6774
// Otherwise, we can take seven bits to calculate the length and the remaining eighth bit
6875
// as continuation bit.
6976
$digit = ord($buffer[$byteIndex]);

0 commit comments

Comments
 (0)