elephant.io icon indicating copy to clipboard operation
elephant.io copied to clipboard

Resolves decoder error if stream data length is greater than 65535

Open kfmdev opened this issue 8 years ago • 2 comments

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

kfmdev avatar Dec 22 '17 06:12 kfmdev

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 ?

Taluu avatar Dec 22 '17 11:12 Taluu

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.

ccff33 avatar Oct 01 '18 18:10 ccff33