Handle orphaned continuation frames

This commit is contained in:
Kovid Goyal 2015-10-25 23:55:31 +05:30
parent f7be2cc60f
commit 02b6e54bf1
2 changed files with 11 additions and 0 deletions

View File

@ -251,9 +251,16 @@ class WebSocketTest(BaseTest):
{'opcode':opcode, 'payload':'f1', 'fin':0}, {'opcode':opcode, 'payload':'f2'}
], close_code=PROTOCOL_ERROR, send_close=False)
client = server.connect()
self.simple_test(client, [{'opcode':0, 'payload':b'non-continuation frame'}, 'some text'], close_code=PROTOCOL_ERROR, send_close=False)
fragments = 'frag1 frag2'.split()
client = server.connect()
self.simple_test(client, [
{'opcode':TEXT, 'payload':fragments[0], 'fin':0}, {'opcode':TEXT, 'payload':fragments[1]}
], [''.join(fragments)])
client = server.connect()
self.simple_test(client, [
{'opcode':TEXT, 'payload':fragments[0], 'fin':0}, (PING, b'pong'), {'opcode':TEXT, 'payload':fragments[1]}
], [(PONG, b'pong'), ''.join(fragments)])

View File

@ -316,6 +316,10 @@ class WebSocketConnection(HTTPConnection):
message_starting = self.current_recv_opcode is None
if message_starting:
if opcode == CONTINUATION:
self.log.error('Client sent continuation frame with no message to continue')
self.websocket_close(PROTOCOL_ERROR, 'Continuation frame without any message to continue')
return
self.current_recv_opcode = opcode
message_finished = frame_finished and is_final_frame_of_message
if message_finished: