diff options
author | Luke Wilde <lukew@serenityos.org> | 2022-03-09 21:33:01 +0000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-10 01:15:00 +0100 |
commit | 1535fe03242af6502f9bb091d5f4aae2552564d9 (patch) | |
tree | 68473b73c593d16720fe97ee287502319b776f3e /Userland | |
parent | 75943503761acd5b83523544202a6f5d9c7aa68d (diff) | |
download | serenity-1535fe03242af6502f9bb091d5f4aae2552564d9.zip |
LibWebSocket: Add to the total read in bytes instead of subtracting
read_length in WebSocket::read_frame is used to track how many bytes we
have read in from the network. However, we was subtracting the number
of read in bytes instead of adding, underflowing it to about the 64-bit
unsigned integer limit.
This effectively limited us to only doing one read from the network.
This was only an issue if the server stalled when sending data,
which is especially common for large payloads. This would also cause us
to go out of sync. This meant when a new frame came in, we would read
the payload data of the previous frame as if it was the frame header
and payload of the next frame.
This allows us to read in the initial payload from Discord Gateway
that describes to the client the servers we are in, the emotes the
server has, the channels it has, etc. For an account that's only in
the Serenity Discord, this was about 20 KB (compressed!)
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWebSocket/WebSocket.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Userland/Libraries/LibWebSocket/WebSocket.cpp b/Userland/Libraries/LibWebSocket/WebSocket.cpp index c667ec27fd..16f557644c 100644 --- a/Userland/Libraries/LibWebSocket/WebSocket.cpp +++ b/Userland/Libraries/LibWebSocket/WebSocket.cpp @@ -437,7 +437,7 @@ void WebSocket::read_frame() auto payload_part = payload_part_result.release_value(); // We read at most "actual_length - read" bytes, so this is safe to do. payload.overwrite(read_length, payload_part.data(), payload_part.size()); - read_length -= payload_part.size(); + read_length += payload_part.size(); } if (is_masked) { |