Skip to content

Commit

Permalink
Gracefully fail to decode empty packets (Fixes #269)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed May 29, 2022
1 parent 3345a59 commit 9c65707
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/engineio/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def encode(self, b64=False):
def decode(self, encoded_packet):
"""Decode a transmitted package."""
self.binary = isinstance(encoded_packet, binary_types)
if not self.binary and len(encoded_packet) == 0:
raise ValueError('Invalid empty packet received')
b64 = not self.binary and encoded_packet[0] == 'b'
if b64:
self.binary = True
Expand Down
4 changes: 4 additions & 0 deletions tests/common/test_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,7 @@ def test_decode_number_packet(self):
def test_binary_non_message_packet(self):
with pytest.raises(ValueError):
packet.Packet(packet.NOOP, b'\x01\x02\x03')

def test_decode_invalid_empty_text_packet(self):
with pytest.raises(ValueError):
packet.Packet(encoded_packet='')

0 comments on commit 9c65707

Please sign in to comment.