Skip to content
This repository has been archived by the owner on Aug 25, 2022. It is now read-only.

Resolves decoder error if stream data length is greater than 65535 #168

Open
kfmdev opened this issue Dec 22, 2017 · 2 comments
Open

Resolves decoder error if stream data length is greater than 65535 #168

kfmdev opened this issue Dec 22, 2017 · 2 comments

Comments

@kfmdev
Copy link

kfmdev commented Dec 22, 2017

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

@Taluu
Copy link
Contributor

Taluu commented Dec 22, 2017

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 ?

@ccff33
Copy link

ccff33 commented Oct 1, 2018

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants