624e162
From af10f458a1590691e4c2f03a499d6c22fdf81cfe Mon Sep 17 00:00:00 2001
624e162
From: Rafael Folco <rafaelfolco@gmail.com>
624e162
Date: Wed, 25 Mar 2015 01:20:25 -0300
624e162
Subject: [PATCH] BUGFIX:  Websocket frame corruption on big-endian #150
624e162
624e162
This patch fixes noVNC endianess problem on handshake.
624e162
It affects noVNC sessions on Big Endian platforms.
624e162
624e162
Fixes #150
624e162
---
624e162
 websockify/websocket.py | 20 ++++++++++++--------
624e162
 1 file changed, 12 insertions(+), 8 deletions(-)
624e162
624e162
diff --git a/websockify/websocket.py b/websockify/websocket.py
624e162
index 1b3dca9..de56af3 100644
624e162
--- a/websockify/websocket.py
624e162
+++ b/websockify/websocket.py
624e162
@@ -118,20 +118,24 @@ class WebSocketRequestHandler(SimpleHTTPRequestHandler):
624e162
         if numpy:
624e162
             b = c = s2b('')
624e162
             if plen >= 4:
624e162
-                mask = numpy.frombuffer(buf, dtype=numpy.dtype('
624e162
-                        offset=hlen, count=1)
624e162
-                data = numpy.frombuffer(buf, dtype=numpy.dtype('
624e162
-                        offset=pstart, count=int(plen / 4))
624e162
+                dtype=numpy.dtype('
624e162
+                if sys.byteorder == 'big':
624e162
+                    dtype = dtype.newbyteorder('>')
624e162
+                mask = numpy.frombuffer(buf, dtype, offset=hlen, count=1)
624e162
+                data = numpy.frombuffer(buf, dtype, offset=pstart,
624e162
+                        count=int(plen / 4))
624e162
                 #b = numpy.bitwise_xor(data, mask).data
624e162
                 b = numpy.bitwise_xor(data, mask).tostring()
624e162
 
624e162
             if plen % 4:
624e162
                 #self.msg("Partial unmask")
624e162
-                mask = numpy.frombuffer(buf, dtype=numpy.dtype('B'),
624e162
-                        offset=hlen, count=(plen % 4))
624e162
-                data = numpy.frombuffer(buf, dtype=numpy.dtype('B'),
624e162
-                        offset=pend - (plen % 4),
624e162
+                dtype=numpy.dtype('B')
624e162
+                if sys.byteorder == 'big':
624e162
+                    dtype = dtype.newbyteorder('>')
624e162
+                mask = numpy.frombuffer(buf, dtype, offset=hlen,
624e162
                         count=(plen % 4))
624e162
+                data = numpy.frombuffer(buf, dtype,
624e162
+                        offset=pend - (plen % 4), count=(plen % 4))
624e162
                 c = numpy.bitwise_xor(data, mask).tostring()
624e162
             return b + c
624e162
         else:
624e162
-- 
624e162
2.3.4
624e162