Skip to content
Permalink
Browse files

Fix websocket data parsing if content is larger than read BUFSIZE; Is…

…sue #181
  • Loading branch information
spaceone committed Nov 2, 2016
1 parent b0df3dd commit 1a7a076223e8846743c3d3666000862cb4c01d5d
Showing with 4 additions and 0 deletions.
  1. +4 −0 circuits/protocols/websocket.py
@@ -49,6 +49,7 @@ def __init__(self, sock=None, data=bytearray(), *args, **kwargs):
self._pending_type = None
self._close_received = False
self._close_sent = False
self._buffer = bytearray()

messages = self._parse_messages(bytearray(data))
for message in messages:
@@ -90,6 +91,7 @@ def _parse_messages(self, data):
msgs = [] # one chunk of bytes may result in several messages
if self._close_received:
return msgs
data = self._buffer + data
while data:
# extract final flag, opcode and masking
final = bool(data[0] & 0x80 != 0)
@@ -111,7 +113,9 @@ def _parse_messages(self, data):
offset += 4
# if not enough bytes available yet, retry after next read
if len(data) - offset < payload_length:
self._buffer += data
break
self._buffer = bytearray()
# rest of _buffer is payload
msg = data[offset:offset + payload_length]
if masking: # unmask

0 comments on commit 1a7a076

Please sign in to comment.
You can’t perform that action at this time.