mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Handle orphaned continuation frames
This commit is contained in:
parent
f7be2cc60f
commit
02b6e54bf1
@ -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)])
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user