sta / websocket-sharp

A C# implementation of the WebSocket protocol client and server
http://sta.github.io/websocket-sharp
MIT License
5.69k stars 1.66k forks source link

Incorrect bitwise calculation/combination? 'WebSocketFrame.ToArray()' #717

Open DennisVM-D2i opened 1 year ago

DennisVM-D2i commented 1 year ago

I get the feeling that the following code line might be faulty:

int num = ((int) ((byte) ((int) ((byte) ((int) ((byte) ((int) ((byte) ((int) ((byte) ((int) this._fin << 1) + this._rsv1) << 1) + this._rsv2) << 1) + this._rsv3) << 4) + this._opcode) << 1) + this._mask) << 7) + (int) this._payloadLength;

And should possibly be replaced with something like this:

int num = ((byte)_fin << 15) + ((byte)_rsv1 << 14) + ((byte)_rsv2 << 13) + ((byte)_rsv3 << 12) + ((byte)_opcode << 8) + ((byte)_mask << 7) + (_payloadLength);

For the '1.0.3-rc11' version (- '1.0.2.59611'?).

Also, is the repo' for the RC version available to the public?

At least it appeared to be the case on the receiving end, and during transit (as seen via Wireshark), as the 'FIN' flag seemed unset upon arrival; although I had converted the DLL to C# code (- was something inadvertently adjusted/lost in the translation?).