Skip to content

Commit a2f5eb9

Browse files
committed
[WS] Fix wslay multi-frame message parsing (again)
We incorrectly assumed that the `payload_length` in the recv start callback of wslay was the final message size, but according to the WebSocket protocol, the payload length always refers to the current frame's payload size. The protocol, in fact, do not include a "message payload" length on purpose to allow sending messages of unknown size without forcing the sender to buffer the whole message (RFC6455 Section 5.4). This means a receiving peer has no way to know beforehand how long a message will be, and needs instead to keep track of the length of each frame until the FIN one is received to properly reconstruct the message at the end.
1 parent 6dc78c8 commit a2f5eb9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

modules/websocket/wsl_peer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,6 @@ void WSLPeer::_wsl_recv_start_callback(wslay_event_context_ptr ctx, const struct
598598
// Get ready to process a data package.
599599
PendingMessage &pm = peer->pending_message;
600600
pm.opcode = op;
601-
pm.payload_size = arg->payload_length;
602601
}
603602
}
604603

@@ -608,6 +607,7 @@ void WSLPeer::_wsl_frame_recv_chunk_callback(wslay_event_context_ptr ctx, const
608607
if (pm.opcode != 0) {
609608
// Only write the payload.
610609
peer->in_buffer.write_packet(arg->data, arg->data_length, nullptr);
610+
pm.payload_size += arg->data_length;
611611
}
612612
}
613613

0 commit comments

Comments
 (0)