yaddesign / phpwebsocket

Automatically exported from code.google.com/p/phpwebsocket
0 stars 0 forks source link

Decode broken when multiple calls same time #59

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Send two frames in a very short time
  socket.send('message1')
  socket.send('message2')

As result, the decoding function does not understand when first frame end and 
second one start, which causes it handle two frame as single. This lead broken 
output.

Decode function is:
    private function decode ($msg) {
        $len = $data = $decoded = $index = null;
        $len = $msg[1] & 127;
        if ($len === 126) {
            $this->masks = substr ($msg, 4, 4);
            $data = substr ($msg, 8);
            $this->initFrame = substr ($msg, 0, 4);
        }
        else if ($len === 127) {
            $this->masks = substr ($msg, 10, 4);
            $data = substr ($msg, 14);
            $this->initFrame = substr ($msg, 0, 10);
        }
        else {
            $this->masks = substr ($msg, 2, 4);
            $data = substr ($msg, 6);
            $this->initFrame = substr ($msg, 0, 2);
        }
        for ($index = 0; $index < strlen ($data); $index++) {
            $decoded .= $data[$index] ^ $this->masks[$index % 4];
        }
        return $decoded;
    }
----------------

Should there be some regonizion when frame end and then attach rest of the 
message to second frame?

Original issue reported on code.google.com by ottovill...@gmail.com on 15 Nov 2012 at 9:35