Skip to content

Commit ee0e1bd

Browse files
committed
handle large packets
1 parent 80b0f56 commit ee0e1bd

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/packet/Factory.php

+13-5
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,23 @@ class Factory
2020
*/
2121
public static function getNextPacket(Version $version, $remainingData)
2222
{
23-
while(isset($remainingData[1])) {
23+
while (isset($remainingData[1])) {
2424
$byte = 1;
25-
$packetLength = 0;
25+
$remainingLength = 0;
26+
$multiplier = 1;
2627
do {
28+
if ($byte >= 6) {
29+
break;
30+
}
31+
2732
$digit = ord($remainingData[$byte]);
28-
$packetLength += $digit;
33+
$remainingLength += ($digit & 127) * $multiplier;
34+
$multiplier *= 128;
2935
$byte++;
30-
} while (($digit & 128) != 0);
31-
$packetLength += 2;
36+
} while (($digit & 128) !== 0);
37+
38+
$packetLength = $byte + $remainingLength;
39+
3240
$nextPacketData = substr($remainingData, 0, $packetLength);
3341
$remainingData = substr($remainingData, $packetLength);
3442

0 commit comments

Comments
 (0)