diff --git a/compliance/test_fuzzingclient.py b/compliance/test_fuzzingclient.py index 7ff19fd..915389e 100644 --- a/compliance/test_fuzzingclient.py +++ b/compliance/test_fuzzingclient.py @@ -34,6 +34,8 @@ for case in range(1, count+1): status = websocket.STATUS_PROTOCOL_ERROR except websocket.WebSocketProtocolException: status = websocket.STATUS_PROTOCOL_ERROR + except websocket.WebSocketPayloadException: + status = websocket.STATUS_INVALID_PAYLOAD except Exception as e: # status = websocket.STATUS_PROTOCOL_ERROR print(traceback.format_exc()) diff --git a/websocket/_abnf.py b/websocket/_abnf.py index 48a230a..9d86c5d 100644 --- a/websocket/_abnf.py +++ b/websocket/_abnf.py @@ -107,6 +107,9 @@ class ABNF(object): if self.rsv1 or self.rsv2 or self.rsv3: raise WebSocketProtocolException("rsv is not implemented, yet") + if self.opcode not in ABNF.OPCODES: + raise WebSocketProtocolException("Invalid opcode " + self.opcode) + if self.opcode == ABNF.OPCODE_PING and not self.fin: raise WebSocketProtocolException("Invalid ping frame.") diff --git a/websocket/_exceptions.py b/websocket/_exceptions.py index 85aa0e3..6de8d1d 100644 --- a/websocket/_exceptions.py +++ b/websocket/_exceptions.py @@ -36,6 +36,12 @@ class WebSocketProtocolException(WebSocketException): """ pass +class WebSocketPayloadException(WebSocketException): + """ + If the webscoket payload is invalid, this exception will be raised. + """ + pass + class WebSocketConnectionClosedException(WebSocketException): """ If remote host closed the connection or some network error happened,