Incorrect header created for payloads longer than 125 bytes using RFC6455 patch
- Dominant language
- PHP
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
```
What steps will reproduce the problem?
1. Apply RFC6455 patch
2. Send a message with a payload larger than 125bytes
3. Websocket clients will not be able to correctly decode the length of the
payload
The problem is with the wrap function not correctly implementing the payload
length section of the web sockets standard. If the payload is longer than
125bytes then a length of 126 or 127 bytes needs to be sent in the payload
length section of the header and an additional 16 bit (with 126 sent in the
length section) or 64 bit (with 127 sent in the length section) unsigned, big
endian integer length also needs to be sent as part of the header. Here is a
fix that works for payload lengths up to 4,294,967,295 or the maximum of a
32-bit unsigned integer. A full implementation should be able to handle payload
lengths up to the maximum of a 64-bit unsigned integer.
function wrap($msg=""){
$length=strlen($msg);
if ($length<126)
$header=chr(0x81).chr($length);
elseif ($length<65536)
$header=chr(0x81).chr(126).pack("n",$length);
else
$header=chr(0x81).chr(127).pack("N",$length);
$msg=$header.$msg;
return $msg;
}
```
Original issue reported on code.google.com by `StevenOk...@gmail.com` on 10 May 2012 at 3:04
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.