varspool / Wrench

A simple PHP WebSocket implementation for PHP 7.1
Do What The F*ck You Want To Public License
596 stars 210 forks source link

Frame handling causes crash #35

Closed Rupert-RR closed 9 years ago

Rupert-RR commented 11 years ago

I'm not sure whether this is from a client trying to connect using an old version of the protocol, or some error on the server side, but whichever it is I think there should be some kind of check in place to prevent a crash.

I got the following error:

PHP Error[8]: Uninitialized string offset: 3
    in file /home/xxxx/Wrench/Frame/HybiFrame.php at line 273

This is because the code:

for ($i = $start; $i <= $end; $i++) {
    $length <<= 8;
    $length  += ord($this->buffer[$i]);
}

assumes that $this->buffer[$i] is set, but I can't see anything to guarantee this (apart from perhaps the specification of the protocol), so I think we should perhaps check that $this->buffer[$i] is set in each iteration.