Skip to content

Commit

Permalink
fix(Net): WebSocket receiveFrame() keeps returning the same frame whe…
Browse files Browse the repository at this point in the history
…n no payload (flags/header only) #4884
  • Loading branch information
obiltschnig committed Feb 27, 2025
1 parent 1facbeb commit 7dd2024
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions Net/src/WebSocketImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ int WebSocketImpl::receiveBytes(void* buffer, int length, int)
throw WebSocketException(Poco::format("Insufficient buffer for payload size %d", payloadLength), WebSocket::WS_ERR_PAYLOAD_TOO_BIG);
}

skipHeader(_receiveState.headerLength);

_receiveState.payload.resize(payloadLength, false);

skipHeader(_receiveState.headerLength);
}
else if (_receiveState.payloadLength > length)
{
Expand Down Expand Up @@ -364,13 +364,16 @@ int WebSocketImpl::receiveBytes(Poco::Buffer<char>& buffer, int, const Poco::Tim
payloadLength = peekHeader(_receiveState);
}
if (payloadLength <= 0)
{
skipHeader(_receiveState.headerLength);
return payloadLength;

skipHeader(_receiveState.headerLength);
}

std::size_t oldSize = buffer.size();
buffer.resize(oldSize + payloadLength);

skipHeader(_receiveState.headerLength);

if (receivePayload(buffer.begin() + oldSize, payloadLength, _receiveState.mask, _receiveState.useMask, 0) != payloadLength)
throw WebSocketException("Incomplete frame received", WebSocket::WS_ERR_INCOMPLETE_FRAME);

Expand All @@ -382,11 +385,14 @@ int WebSocketImpl::receiveBytes(Poco::Buffer<char>& buffer, int, const Poco::Tim
{
int payloadLength = peekHeader(_receiveState);
if (payloadLength <= 0)
{
skipHeader(_receiveState.headerLength);
return payloadLength;

skipHeader(_receiveState.headerLength);
}

_receiveState.payload.resize(payloadLength, false);

skipHeader(_receiveState.headerLength);
}
int payloadOffset = _receiveState.payloadLength - _receiveState.remainingPayloadLength;
int n = receivePayload(_receiveState.payload.begin() + payloadOffset, _receiveState.remainingPayloadLength, _receiveState.mask, _receiveState.useMask, _receiveState.maskOffset);
Expand Down

0 comments on commit 7dd2024

Please sign in to comment.