Olivine-Labs/Alchemy-Websockets — Issue #5: DataFrame.Wrap() modifies provided byte array
Author: ShyRed
Created: 2011-10-20 06:47:46+00:00
State: open

The ```DataFrame.Send()``` method passes it's given parameter Data byte array to the private method ```Mask()``` which in turns manipulates the byte array.

As a result, since arrays types are reference types ( see http://msdn.microsoft.com/en-us/library/9b9dty7d.aspx ), the Send() method modifies the original provided byte array.

Example for better understanding:

```c#
server.DefaultOnReceive = (ctx) =>
{
byte[] data = ctx.DataFrame.ToBytes();
foreach (UserContext context in clients)
if (context.ClientAddress != ctx.ClientAddress)
context.Send(data);
};
```

In the foreach loop the first client will receive a correct message from the server. The second client will receive damaged data, since the previous call to the ```Send()``` method modified the data-byte array.