diff options
| author | Solly <directxman12+github@gmail.com> | 2015-04-07 12:51:52 -0400 |
|---|---|---|
| committer | Solly <directxman12+github@gmail.com> | 2015-04-07 12:51:52 -0400 |
| commit | ac9d357c870d5ddda1708f7af52b0e00d04b782c (patch) | |
| tree | 7f3dfec2009f49f1334e0948935f87536af0b005 | |
| parent | ce07749223b4ebf1990bb5be51e47c4f8887a92f (diff) | |
| parent | af10f458a1590691e4c2f03a499d6c22fdf81cfe (diff) | |
| download | websockify-ac9d357c870d5ddda1708f7af52b0e00d04b782c.tar.gz | |
Merge pull request #161 from rafaelfolco/bug/150-websocket-bigendian
BUGFIX: Websocket frame corruption on big-endian #150
| -rw-r--r-- | websockify/websocket.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/websockify/websocket.py b/websockify/websocket.py index 1b3dca9..de56af3 100644 --- a/websockify/websocket.py +++ b/websockify/websocket.py @@ -118,20 +118,24 @@ class WebSocketRequestHandler(SimpleHTTPRequestHandler): if numpy: b = c = s2b('') if plen >= 4: - mask = numpy.frombuffer(buf, dtype=numpy.dtype('<u4'), - offset=hlen, count=1) - data = numpy.frombuffer(buf, dtype=numpy.dtype('<u4'), - offset=pstart, count=int(plen / 4)) + dtype=numpy.dtype('<u4') + if sys.byteorder == 'big': + dtype = dtype.newbyteorder('>') + mask = numpy.frombuffer(buf, dtype, offset=hlen, count=1) + data = numpy.frombuffer(buf, dtype, offset=pstart, + count=int(plen / 4)) #b = numpy.bitwise_xor(data, mask).data b = numpy.bitwise_xor(data, mask).tostring() if plen % 4: #self.msg("Partial unmask") - mask = numpy.frombuffer(buf, dtype=numpy.dtype('B'), - offset=hlen, count=(plen % 4)) - data = numpy.frombuffer(buf, dtype=numpy.dtype('B'), - offset=pend - (plen % 4), + dtype=numpy.dtype('B') + if sys.byteorder == 'big': + dtype = dtype.newbyteorder('>') + mask = numpy.frombuffer(buf, dtype, offset=hlen, count=(plen % 4)) + data = numpy.frombuffer(buf, dtype, + offset=pend - (plen % 4), count=(plen % 4)) c = numpy.bitwise_xor(data, mask).tostring() return b + c else: |
