Verify contination frames.

This commit is contained in:
Chris Ross 2014-10-23 08:24:19 -07:00
parent 31c76a0032
commit e8c4985322
1 changed files with 12 additions and 6 deletions

View File

@ -215,8 +215,14 @@ namespace Microsoft.AspNet.WebSockets.Protocol
await ReadNextFrameAsync(cancellationToken);
}
// Handle fragmentation, remember the first frame type
int opCode = _frameInProgress.OpCode;
if (opCode == Constants.OpCodes.CloseFrame)
{
return await ProcessCloseFrameAsync(cancellationToken);
}
// Handle fragmentation, remember the first frame type
if (opCode == Constants.OpCodes.ContinuationFrame)
{
if (!_firstDataOpCode.HasValue)
@ -230,11 +236,6 @@ namespace Microsoft.AspNet.WebSockets.Protocol
_firstDataOpCode = opCode;
}
if (opCode == Constants.OpCodes.CloseFrame)
{
return await ProcessCloseFrameAsync(cancellationToken);
}
// Make sure there's at least some data in the buffer
int bytesToBuffer = (int)Math.Min((long)_receiveBuffer.Length, _frameBytesRemaining);
await EnsureDataAvailableOrReadAsync(bytesToBuffer, cancellationToken);
@ -329,6 +330,11 @@ namespace Microsoft.AspNet.WebSockets.Protocol
_frameInProgress = null;
}
}
else if (_firstDataOpCode.HasValue && _frameInProgress.OpCode != Constants.OpCodes.ContinuationFrame)
{
// A data frame is already in progress, but this new frame is not a continuation frame.
await SendErrorAbortAndThrow(WebSocketCloseStatus.ProtocolError, "Expected a continuation frame: " + _frameInProgress.OpCode, cancellationToken);
}
}
private async Task EnsureDataAvailableOrReadAsync(int bytesNeeded, CancellationToken cancellationToken)