elephant.io
elephant.io copied to clipboard
Resolves decoder error if stream data length is greater than 65535
Decoder.php
Add to
public function decode()
{
.........
- if ($length > 125) {
- $payloadOffset = (0xFFFF < $length && 0xFFFFFFFF >= $length) ? 6 : 4;
- }
-
+ if ($length <= 125) {
+ $payloadOffset = 2;
+ }elseif ($length >= 126 && $length <= 65535) {
+ $payloadOffset = 4;
+ }elseif($length >= 65536){
+ $payloadOffset = 10;
+ }
+
.........
}
Add to
public function count()
{
.............
-
- if ($length == 126 || $length == 127) {
- $length = unpack('H*', substr($this->payload, 2, ($length == 126 ? 2 : 4)));
- $length = hexdec($length[1]);
- }
+
+ if ($length == 126) {
+ $length = unpack('H*', substr($this->payload, 2, ($length == 126 ? 2 : 4)));
+ $length = hexdec($length[1]);
+ }
+ elseif ($length == 127) {
+ $length = unpack('H*', substr($this->payload, 2, ($length == 127 ? 8 : 8)));
+ $length = hexdec($length[1]);
+ }
................
}
p.s: Wisembly elephant.io socket.io php message cut length decoder error 16bit 32bit 64bit read error emit
Hum, actually it should support length greater than 65535, but it won't support length greater than 4294967295 (32bits).
The things you are proposing IIRC is that the payloadOffset is wrong, right ? IIRC, the specs are saying the offset should not be that big, unless something has changed since then ?
Hi, Just had a similar issue and this code solved it. Thanks a lot. Doing var_export for the messages, normal would look like that:
'▒~%▒42[
Whereas the bigger ones come like that:
'▒' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '▒#42[
Socket.io version is 2.0.3.