BUGFIX: Websocket frame corruption on big-endian #150

This patch fixes noVNC endianess problem on handshake.
It affects noVNC sessions on Big Endian platforms.

Fixes #150
This commit is contained in:
Rafael Folco 2015-03-25 01:20:25 -03:00
parent 19b558e4cd
commit af10f458a1
1 changed files with 12 additions and 8 deletions

View File

@ -118,20 +118,24 @@ class WebSocketRequestHandler(SimpleHTTPRequestHandler):
if numpy: if numpy:
b = c = s2b('') b = c = s2b('')
if plen >= 4: if plen >= 4:
mask = numpy.frombuffer(buf, dtype=numpy.dtype('<u4'), dtype=numpy.dtype('<u4')
offset=hlen, count=1) if sys.byteorder == 'big':
data = numpy.frombuffer(buf, dtype=numpy.dtype('<u4'), dtype = dtype.newbyteorder('>')
offset=pstart, count=int(plen / 4)) 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).data
b = numpy.bitwise_xor(data, mask).tostring() b = numpy.bitwise_xor(data, mask).tostring()
if plen % 4: if plen % 4:
#self.msg("Partial unmask") #self.msg("Partial unmask")
mask = numpy.frombuffer(buf, dtype=numpy.dtype('B'), dtype=numpy.dtype('B')
offset=hlen, count=(plen % 4)) if sys.byteorder == 'big':
data = numpy.frombuffer(buf, dtype=numpy.dtype('B'), dtype = dtype.newbyteorder('>')
offset=pend - (plen % 4), mask = numpy.frombuffer(buf, dtype, offset=hlen,
count=(plen % 4)) count=(plen % 4))
data = numpy.frombuffer(buf, dtype,
offset=pend - (plen % 4), count=(plen % 4))
c = numpy.bitwise_xor(data, mask).tostring() c = numpy.bitwise_xor(data, mask).tostring()
return b + c return b + c
else: else: