-
Notifications
You must be signed in to change notification settings - Fork 1.5k
WebSocket data handler does not check opcode #9207
Description
The WebSocket data handler in ROOT is not complete
The data handler (as defined in line 136 in TCivetWeb.cxx) only checks the fin bit (code & 0x0f) bit but not the opcode (code & 0x0f), which may leads to unexpected behaviour in some circumstance.
Optional: both fin and opcode need to be checked to determine the type of frame received.
As stated in RF4855, the the fin bit and opcode work together to represent the state of the frame. As shown below, the fin (standing for finished) only set for frames contain a complete message (single frame message), or the last frames of multi-frame messages. The opcode indicates the type of frames, i.e., continuation, text, binary, or closing. For multi-frame messages, the opcode indicates the text or binary nature only in the first frame, and the opcode set to zero for the rest of the frames.
- single frame:
fin = 1andopcode = 1,2,8(1: text; 2: binary; 8 closing); - cont'd frame - 1st:
fin = 0andopcode = 1,2(1: text; 2: binary); - cont'd frame - 2..(n-1)-th:
fin = 0andopcode = 0; - cont'd frame - n-th (last):
fin = 1andopcode = 0; - closing:
fin = 1andopcode = 8.
Only use fin may lead to two problems:
- the closing message from client will be interpreted as data. In my case, I receive two bytes (0x03, 0xC5).
- the binary or text nature of the multi-frame message will not be interpreted, because this is only indicate in the first frame. This may not be an issue, though, because the single-frame message in CivetWeb can be as long as 131,000 bytes, which is long enough for most communication from clients.
I hope this can be fixed in the future release.