Skip to content

Fix MessagePack message size determination #111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions signalrcore/protocol/messagepack_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,24 @@ def parse_messages(self, raw):
try:
messages = []
offset = 0
max_length_prefix_size = 5
num_bits_to_shift = [0, 7, 14, 21, 28]
while offset < len(raw):
length = msgpack.unpackb(raw[offset: offset + 1])
values = msgpack.unpackb(raw[offset + 1: offset + length + 1])
offset = offset + length + 1
length = 0
num_bytes = 0
while True:
byte_read = raw[offset + num_bytes]
length |= (byte_read & 0x7F) << num_bits_to_shift[num_bytes]
num_bytes += 1
if byte_read & 0x80 == 0:
break
if offset == max_length_prefix_size or offset + num_bytes > len(
raw
):
raise Exception("Cannot read message length")
offset = offset + num_bytes
values = msgpack.unpackb(raw[offset: offset + length])
offset = offset + length
message = self._decode_message(values)
messages.append(message)
except Exception as ex:
Expand Down