-
Notifications
You must be signed in to change notification settings - Fork 627
Description
Great library. Fun bug in source/NetCoreServer/WebSocket.cs: :o)
PrepareSendFrame(): size should be long (It doesn't work correctly with size > 0xFFFF)
public void PrepareSendFrame(byte opcode, bool mask, ReadOnlySpan buffer, int status = 0)
{
int size = buffer.Length; //todo: long size
...
{
WsSendBuffer.Append((byte)(127 | (mask ? 0x80 : 0)));
for (int i = 7; i >= 0; i--)
WsSendBuffer.Append((byte)((size >> (8 * i)) & 0xFF)); //NOTE: (int)123456 >> 48 = 1 in C#
}
Its strange but true:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/bitwise-and-shift-operators#shift-count-of-the-shift-operators
For the x << count, x >> count, and x >>> count expressions, the actual shift count depends on the type of x as follows:
If the type of x is int or uint, the shift count is defined by the low-order five bits of the right-hand operand. That is, the shift count is computed from count & 0x1F (or count & 0b_1_1111).
If the type of x is long or ulong, the shift count is defined by the low-order six bits of the right-hand operand. That is, the shift count is computed from count & 0x3F (or count & 0b_11_1111).