Skip to content

Encoding error when dash in payload #675

@Nicholas42

Description

@Nicholas42

If you have the following server (Version is 5.2.0):

from flask import Flask
from flask_socketio import SocketIO

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)


@socketio.on('test')
def test(arg):
    print(arg)


if __name__ == '__main__':
    socketio.run(app)

and let the following client run:

import socketio

sio = socketio.Client()

if __name__ == '__main__':
    sio.connect('http://127.0.0.1:5000')
    sio.emit('test', 'this is longer than 10 chars-' )
    sio.wait()

You get the following error:

message handler error
Traceback (most recent call last):
  File "/home/nicholas/projects/btc-flask/venv/lib/python3.9/site-packages/engineio/server.py", line 596, in _trigger_event
    return self.handlers[event](*args)
  File "/home/nicholas/projects/btc-flask/venv/lib/python3.9/site-packages/socketio/server.py", line 738, in _handle_eio_message
    pkt = packet.Packet(encoded_packet=data)
  File "/home/nicholas/projects/btc-flask/venv/lib/python3.9/site-packages/socketio/packet.py", line 40, in __init__
    self.attachment_count = self.decode(encoded_packet)
  File "/home/nicholas/projects/btc-flask/venv/lib/python3.9/site-packages/socketio/packet.py", line 83, in decode
    raise ValueError('too many attachments')
ValueError: too many attachments

If you look at the corresponding code, you see the following:

# in:    def decode(self, encoded_packet):
        
        dash = ep.find('-')
        if dash > 10:
            raise ValueError('too many attachments')

It seems like the program tries to do some decoding and there a dash should be separator, but there is none. Hence the dash in the back of the payload is found and too far in the back.

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions